java.lang.Object | |||
↳ | java.io.Reader | ||
↳ | java.io.FilterReader | ||
↳ | java.io.PushbackReader |
Wraps an existing
Reader
and adds functionality to "push back"
characters that have been read, so that they can be read again. Parsers may
find this useful. The number of characters which may be pushed back can be
specified during construction. If the buffer of pushed back bytes is empty,
characters are read from the underlying reader.
[Expand]
Inherited Fields
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.io.FilterReader
|
|||||||||||
From class
java.io.Reader
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Constructs a new
PushbackReader
with the specified reader as
source.
|
||||||||||
|
Constructs a new
PushbackReader
with
in
as source reader.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Closes this reader.
|
||||||||||
|
Marks the current position in this stream.
|
||||||||||
|
Indicates whether this reader supports the
mark(int)
and
reset()
methods.
|
||||||||||
|
Reads a single character from this reader and returns it as an integer
with the two higher-order bytes set to 0.
|
||||||||||
|
Reads up to
count
characters from this reader and stores them in
character array
buffer
starting at
offset
.
|
||||||||||
|
Indicates whether this reader is ready to be read without blocking.
|
||||||||||
|
Resets this reader to the last marked position.
|
||||||||||
|
Skips
charCount
characters in this reader.
|
||||||||||
|
Pushes a subset of the characters in
buffer
back to this reader.
|
||||||||||
|
Pushes all the characters in
buffer
back to this reader.
|
||||||||||
|
Pushes the specified character
oneChar
back to this reader.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.io.FilterReader
|
|||||||||||
From class
java.io.Reader
|
|||||||||||
From class
java.lang.Object
|
|||||||||||
From interface
java.io.Closeable
|
|||||||||||
From interface
java.lang.AutoCloseable
|
|||||||||||
From interface
java.lang.Readable
|
Constructs a new
PushbackReader
with the specified reader as
source. The size of the pushback buffer is set to the default value of 1
character.
in | the source reader. |
---|
Constructs a new
PushbackReader
with
in
as source reader.
The size of the pushback buffer is set to
size
.
in | the source reader. |
---|---|
size | the size of the pushback buffer. |
IllegalArgumentException |
if
size
is negative.
|
---|
Closes this reader. This implementation closes the source reader and releases the pushback buffer.
IOException | if an error occurs while closing this reader. |
---|
Marks the current position in this stream. Setting a mark is not
supported in this class; this implementation always throws an
IOException
.
readAheadLimit | the number of character that can be read from this reader before the mark is invalidated; this parameter is ignored. |
---|
IOException | if this method is called. |
---|
Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0. Returns -1 if the end of the reader has been reached. If the pushback buffer does not contain any available characters then a character from the source reader is returned. Blocks until one character has been read, the end of the source reader is detected or an exception is thrown.
IOException | if this reader is closed or an I/O error occurs while reading from this reader. |
---|
Reads up to
count
characters from this reader and stores them in
character array
buffer
starting at
offset
. Characters are
read from the pushback buffer first, then from the source reader if more
bytes are required. Blocks until
count
characters have been read,
the end of the source reader is detected or an exception is thrown.
Returns the number of bytes read or -1 if the end of the source reader has been reached.
IndexOutOfBoundsException |
if
offset < 0 || count < 0 || offset + count > buffer.length
.
|
---|---|
IOException | if this reader is closed or another I/O error occurs while reading from this reader. |
Indicates whether this reader is ready to be read without blocking.
Returns
true
if this reader will not block when
read
is
called,
false
if unknown or blocking will occur.
true
if the receiver will not block when
read()
is called,
false
if unknown
or blocking will occur.
IOException | if this reader is closed or some other I/O error occurs. |
---|
Resets this reader to the last marked position. Resetting the reader is
not supported in this class; this implementation always throws an
IOException
.
IOException | if this method is called. |
---|
Skips
charCount
characters in this reader. This implementation skips
characters in the pushback buffer first and then in the source reader if
necessary.
IllegalArgumentException |
if
charCount < 0
.
|
---|---|
IOException | if this reader is closed or another I/O error occurs. |
Pushes a subset of the characters in
buffer
back to this reader.
The subset is defined by the start position
offset
within
buffer
and the number of characters specified by
length
.
The bytes are pushed back in such a way that the next byte read from this
stream is
buffer[offset]
, then
buffer[1]
and so on.
If this stream's internal pushback buffer cannot store the selected
subset of
buffer
, an
IOException
is thrown. Parts of
buffer
may have already been copied to the pushback buffer when
the exception is thrown.
buffer | the buffer containing the characters to push back to this reader. |
---|---|
offset |
the index of the first byte in
buffer
to push back.
|
length | the number of bytes to push back. |
IndexOutOfBoundsException |
if
offset < 0
or
count < 0
, or if
offset + count
is greater than the length of
buffer
.
|
---|---|
IOException |
if this reader is closed or the free space in the internal
pushback buffer is not sufficient to store the selected
contents of
buffer
.
|
NullPointerException |
if
buffer
is
null
.
|
Pushes all the characters in
buffer
back to this reader. The
characters are pushed back in such a way that the next character read
from this reader is buffer[0], then buffer[1] and so on.
If this reader's internal pushback buffer cannot store the entire
contents of
buffer
, an
IOException
is thrown. Parts of
buffer
may have already been copied to the pushback buffer when
the exception is thrown.
buffer | the buffer containing the characters to push back to this reader. |
---|
IOException |
if this reader is closed or the free space in the internal
pushback buffer is not sufficient to store the contents of
buffer
.
|
---|
Pushes the specified character
oneChar
back to this reader. This
is done in such a way that the next character read from this reader is
(char) oneChar
.
If this reader's internal pushback buffer cannot store the character, an
IOException
is thrown.
oneChar | the character to push back to this stream. |
---|
IOException | if this reader is closed or the internal pushback buffer is full. |
---|