The docs for InputStream.read(bytes) say "This method blocks until input data is available, end of file is detected, or an exception is thrown."
However, java.io.FileInputStream extends java.io.InputStream
and the docs for FileInputStream.read(bytes) state no such guarantee:
* Reads up to {@code b.length} bytes of data from this input
* stream into an array of bytes. This method blocks until some input
* is available.
In practice, FileInputStream can indeed return before all the input is available, so it seems both the docs and the implementation do not follow the contract of InputStream.
Is this a bug? Is it a known bug?
UPDATE: to clarify: System.in is a FileInputStream. I am seeing System.in.read(buf) return a nonzero int that is neither all of the bytes, nor -1. If I use System.in.readNBytes(buf, 0, theNumberOfBytesIAmExpecting) then I get all the bytes the sender is sending.
readhas never been specified to return any particular number of bytes, in either class.readNBytesis specifically guaranteed to return the number of requested bytes, unless EOF is reached first.