public class TextReader extends Reader
Constructor and Description |
---|
TextReader(InputStream in)
Create a TextReader which decodes characters from an InputStream
using the default codec and default buffer size.
|
TextReader(InputStream in,
int bufferSize)
Create a TextReader which decodes characters from an InputStream
using the default codec.
|
TextReader(InputStream in,
int bufferSize,
TextCodec codec)
Create a TextReader which decodes characters from an InputStream.
|
TextReader(InputStream in,
TextCodec codec)
Create a TextReader which decodes characters from an InputStream
using the default buffer size.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the stream.
|
int |
read()
Reads an char from the input stream and returns it
as an int in the range of 0-65535.
|
int |
read(char[] buf,
int offset,
int count)
Read chars from a stream and stores them into a caller
supplied buffer.
|
String |
readLine()
Read a full line of text from the input and append it to the destination CharArray.
|
int |
readLine(CharArray destination)
Read a full line of text from the input and append it to the destination CharArray.
|
public TextReader(InputStream in, int bufferSize, TextCodec codec)
in
- The InputStream to read from.bufferSize
- the size of the internal buffer to use when reading bytes.codec
- the TextCodec to use for converting bytes into characters.public TextReader(InputStream in)
in
- The InputStream to read from.public TextReader(InputStream in, int bufferSize)
in
- The InputStream to read from.bufferSize
- the size of the buffer to use.public TextReader(InputStream in, TextCodec codec)
in
- The InputStream to read from.codec
- the TextCodec to use for converting bytes into characters.public int read(char[] buf, int offset, int count) throws IOException
Reader
offset
into the buffer and attempts to read len
chars. This method
can return before reading the number of chars requested. The actual
number of chars read is returned as an int. A -1 is returned to indicate
the end of the stream.
This method will block until some data can be read.
This method operates by calling the single char read()
method
in a loop until the desired number of chars are read. The read loop
stops short if the end of the stream is encountered or if an IOException
is encountered on any read operation except the first. If the first
attempt to read a chars fails, the IOException is allowed to propagate
upward. And subsequent IOException is caught and treated identically
to an end of stream condition. Subclasses can (and should if possible)
override this method to provide a more efficient implementation.
read
in class Reader
buf
- The array into which the chars read should be storedoffset
- The offset into the array to start storing charsIOException
- If an error occurs.public int read() throws IOException
Reader
This method will block until the char can be read.
read
in class Reader
IOException
- If an error occurspublic void close() throws IOException
Reader
IOException
.close
in class Reader
IOException
- If an error occurspublic int readLine(CharArray destination) throws IOException
destination
- a destination CharArray to write the characters to.IOException
- if an IO or text decoding error occurs.public String readLine() throws IOException
IOException
- if an IO or text decoding error occurs.