ByteArrayInputStream method available()?
Let's look into Sun's ByteArrayInputStream method available:
/**
* Returns the number of bytes that can be read from this input
* stream without blocking.
* The value returned is
* <code>count - pos</code>,
* which is the number of bytes remaining to be read from the input buffer.
*
* @return the number of bytes that can be read from the input stream
* without blocking.
*/
publicsynchronizedint available(){
return count - pos;
}
What do they mean in sentence "can be read from this input
stream without blocking." ?
What blocking?
Blocking is waiting for more input (bytes here) that isn't currently"available".
This method is defined by the InputStream class, so the definition is rather abstract.
An easy example to demonstrate the principal would be a socket connection from which u obtain an input stream (which might or might not be a ByteArrayInputStream).
The available() method returns how many bytes are stored "locally" (i.e. in an internal buffer) that were already read from the remote machine. After finishing reading these bytes, an attempt to read more would result with the read() method blocking till the remote machine sends more data.