java.io.InputStreamReader
InputStreamReader is class for turning a byte Stream into a character Stream.
Data read from the source input stream is converted into characters by either
a default or provided character converter. By default, the encoding is
assumed to ISO8859_1. The InputStreamReader contains a buffer of bytes read
from the source input stream and converts these into characters as needed.
The buffer size is 8K.
Known Direct Subclasses
| FileReader |
FileReader is class for turning a file into a character Stream. |
Summary
| protected |
|
|
Object |
lock |
The object used to synchronize access to the reader. |
Public Constructors
Public Methods
Methods inherited
from class
java.io.Reader
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Public Constructors
public
InputStreamReader(InputStream in)
Constructs a new InputStreamReader on the InputStream
in.
Now character reading can be filtered through this InputStreamReader.
This constructor assumes the default conversion of ISO8859_1
(ISO-Latin-1).
Parameters
| in
| the InputStream to convert to characters.
|
public
InputStreamReader(InputStream in, String enc)
Constructs a new InputStreamReader on the InputStream
in.
Now character reading can be filtered through this InputStreamReader.
This constructor takes a String parameter
enc which is the
name of an encoding. If the encoding cannot be found, an
UnsupportedEncodingException error is thrown.
Parameters
| in
| the InputStream to convert to characters. |
| enc
| a String describing the character converter to use. |
Constructs a new InputStreamReader on the InputStream
in
and CharsetDecoder
dec. Now character reading can be
filtered through this InputStreamReader.
Parameters
| in
| the InputStream to convert to characters |
| dec
| a CharsetDecoder used by the character conversion
|
public
InputStreamReader(InputStream in, Charset charset)
Constructs a new InputStreamReader on the InputStream
in
and Charset
charset. Now character reading can be
filtered through this InputStreamReader.
Parameters
| in
| the InputStream to convert to characters |
| charset
| the Charset that specify the character converter
|
Public Methods
public
void
close()
Close this InputStreamReader. This implementation closes the source
InputStream and releases all local storage.
Throws
| IOException
| If an error occurs attempting to close this
InputStreamReader.
|
public
String
getEncoding()
Answer the String which identifies the encoding used to convert bytes to
characters. The value
null is returned if this Reader has
been closed.
Returns
- the String describing the converter or null if this Reader is
closed.
public
int
read(char[] buf, int offset, int length)
Reads at most
count characters from this Reader and stores
them at
offset in the character array
buf.
Returns the number of characters actually read or -1 if the end of reader
was encountered. The bytes are either obtained from converting bytes in
this readers buffer or by first filling the buffer from the source
InputStream and then reading from the buffer.
Parameters
| buf
| character array to store the read characters |
| offset
| offset in buf to store the read characters |
| length
| maximum number of characters to read |
Returns
- the number of characters read or -1 if end of reader.
Throws
| IOException
| If the InputStreamReader is already closed or some other IO
error occurs.
|
public
int
read()
Reads a single character from this InputStreamReader and returns the
result as an int. The 2 higher-order characters are set to 0. If the end
of reader was encountered then return -1. The byte value is either
obtained from converting bytes in this readers buffer or by first filling
the buffer from the source InputStream and then reading from the buffer.
Returns
- the character read or -1 if end of reader.
Throws
| IOException
| If the InputStreamReader is already closed or some other IO
error occurs.
|
public
boolean
ready()
Answers a
boolean indicating whether or not this
InputStreamReader is ready to be read without blocking. If the result is
true, the next
read() will not block. If
the result is
false this Reader may or may not block when
read() is sent. This implementation answers
true if there are bytes available in the buffer or the
source InputStream has bytes available.
Returns
true if the receiver will not block when
read() is called, false if unknown
or blocking will occur.
Throws
| IOException
| If the InputStreamReader is already closed or some other IO
error occurs.
|