BOMInputStream.read(byte) returns 0 when it should return -1.
This is not a valid action (unless buf.length == 0) and can cause problems, e.g. "java.io.IOException: Underlying input stream returned zero bytes - at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:268)"
From java.io.InputStream.read(byte) JavaDocs: "If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b."
Suggested fix, change line 287 of BOMInputStream.java from
return (secondCount < 0) ? firstCount : firstCount + secondCount;
return (secondCount < 0) ? (firstCount > 0 ? firstCount : -1) : firstCount + secondCount;