InputStreamReader

Name

The InputStreamReader class
is a bridge between the byte-oriented world of the InputStream
class and the character-oriented world of the Reader
class. The InputStreamReader
represents a character stream, but it gets its input from an underlying
byte stream. An encoding scheme is responsible for translating the bytes
to Unicode characters. An InputStreamReader
can be created using an explicit encoding scheme or a default encoding
scheme.

For example, to read an ISO-8859-5 byte stream as a Unicode character stream,
you can construct an InputStreamReader
with the encoding "8859_5" as follows:

InputStreamReader inr = new InputStreamReader(in, "8859_5");

Each time you read from an InputStreamReader
object, bytes may be read from the underlying byte stream. To improve efficiency,
you may want to wrap the InputStreamReader
in a BufferedReader.

The next character of data or -1 if the end of the stream is encountered.

Throws

IOException

If any kind
of I/O error occurs.

Overrides

Reader.read()

Description

This method reads a character of input. The method returns the next
character that has been read and converted from the underlying
byte-oriented InputStream. The
InputStreamReader class uses buffering internally,
so this method returns immediately unless the buffer is empty. If the
buffer is empty, a new block of bytes is read from the
InputStream and converted to characters. The method
blocks until the character is read, the end of stream is encountered,
or an exception is thrown.

The actual number of characters read or -1 if the end of the stream is
encountered immediately.

Throws

IOException

If any kind
of I/O error occurs.

Overrides

Reader.read(char[], int, int)

Description

This method reads up to len
characters of input into the given array starting at index off.
The InputStreamReader class
uses buffering internally, so this method returns immediately if there
is enough data in the buffer. If there is not enough data, a new block
of bytes is read from the InputStream
and converted to characters. The method blocks until some data is available.

This method returns a boolean
value that indicates whether or not the reader is ready to be read. If
there is data available in the internal buffer or if there are bytes available
to be read from the underlying byte stream, the method returns true.
Otherwise it returns false.