public abstract class Reader extends AutoCloseable
The base class for all readers. A reader is a means of reading data from a source in a character-wise manner.
This abstract class does not provide a fully working implementation, so it needs to be subclassed, and at least the
read(char[], int, int)
and AutoCloseable.close()
methods needs to be overridden. Overriding some of the
non-abstract methods is also often advised, since it might result in higher efficiency.
Constructor and Description |
---|
Reader() |
Modifier and Type | Method and Description |
---|---|
int |
read()
Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0.
|
int |
read(char[] buffer)
Reads characters from this reader and stores them in the character array
buf starting at offset 0. |
abstract int |
read(char[] buffer,
int offset,
int count)
Reads at most
count characters from this reader and stores them at offset in the character array
buf . |
close
public int read()
IOException
- if this reader is closed or some other I/O error occurspublic int read(char[] buffer)
buf
starting at offset 0.
Returns the number of characters actually read or -1 if the end of the reader has been reached.buffer
- character array to store the characters read.IOException
- if this reader is closed or some other I/O error occurspublic abstract int read(char[] buffer, int offset, int count)
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 the reader has been reached.buffer
- the character array to store the characters readoffset
- the initial position in buffer
to store the characters read from this readercount
- the maximum number of characters to readIOException
- if this reader is closed or some other I/O error occurs