BufferedInputStream.read

BufferedInputStream.read

Class Overview | Class Members | This Package | All Packages

Syntax 1
public synchronized int read() throws IOException
Returns
the next byte of data, or -1 if the end of the stream is reached.
Description
Reads the next byte of data from this buffered input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

The read method of BufferedInputStream returns the next byte of data from its buffer if the buffer is not empty. Otherwise, it refills the buffer from the underlying input stream and returns the next character, if the underlying stream has not returned an end-of-stream indicator.

Exceptions
IOException if an I/O error occurs.
Overrides
read in class FilterInputStream
See Also
in



Syntax 2
public synchronized int read( byte b[], int off, int len ) throws IOException
Parameters
b
destination buffer.
off
offset at which to start storing bytes.
len
maximum number of bytes to read.
Returns
the number of bytes read, or -1 if the end of the stream has been reached.
Description
Reads bytes into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If this stream's buffer is not empty, bytes are copied from it into the array argument. Otherwise, the buffer is refilled from the underlying input stream and, unless the stream returns an end-of-stream indication, the array argument is filled with characters from the newly-filled buffer.

As an optimization, if the buffer is empty, the mark is not valid, and len is at least as large as the buffer, then this method will read directly from the underlying stream into the given array. Thus redundant BufferedInputStreams will not copy data unnecessarily.

Exceptions
IOException if an I/O error occurs.
Overrides
read in class FilterInputStream