java.lang.Object | |||
↳ | java.io.InputStream | ||
↳ | java.io.FilterInputStream | ||
↳ | java.io.PushbackInputStream |
Wraps an existing InputStream
and adds functionality to "push back"
bytes that have been read, so that they can be read again. Parsers may find
this useful. The number of bytes which may be pushed back can be specified
during construction. If the buffer of pushed back bytes is empty, bytes are
read from the underlying input stream.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
buf | The buffer that contains pushed-back bytes. | ||||||||||
pos | The current position within buf . |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.io.FilterInputStream
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
PushbackInputStream with the specified input
stream as source. | |||||||||||
Constructs a new
PushbackInputStream with in as source
input stream. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the number of bytes that are available before this stream will
block.
| |||||||||||
Closes this stream.
| |||||||||||
Marks the current position in this stream.
| |||||||||||
Indicates whether this stream supports the
mark(int) and
reset() methods. | |||||||||||
Reads at most
length bytes from this stream and stores them in
the byte array buffer starting at offset . | |||||||||||
Reads a single byte from this stream and returns it as an integer in the
range from 0 to 255.
| |||||||||||
Resets this stream to the last marked position.
| |||||||||||
Skips
count bytes in this stream. | |||||||||||
Pushes all the bytes in
buffer back to this stream. | |||||||||||
Pushes a subset of the bytes in
buffer back to this stream. | |||||||||||
Pushes the specified byte
oneByte back to this stream. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.io.FilterInputStream
| |||||||||||
From class java.io.InputStream
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface java.io.Closeable
|
The current position within buf
. A value equal to
buf.length
indicates that no bytes are available. A value of 0
indicates that the buffer is full.
Constructs a new PushbackInputStream
with the specified input
stream as source. The size of the pushback buffer is set to the default
value of 1 byte.
in | the source input stream. |
---|
Constructs a new PushbackInputStream
with in
as source
input stream. The size of the pushback buffer is set to size
.
in | the source input stream. |
---|---|
size | the size of the pushback buffer. |
IllegalArgumentException | if size is negative.
|
---|
Returns the number of bytes that are available before this stream will block. This is the sum of the bytes available in the pushback buffer and those available from the source stream.
IOException | if this stream is closed or an I/O error occurs in the source stream. |
---|
Closes this stream. This implementation closes the source stream and releases the pushback buffer.
IOException | if an error occurs while closing this stream. |
---|
Marks the current position in this stream. Setting a mark is not supported in this class; this implementation does nothing.
readlimit | the number of bytes that can be read from this stream before the mark is invalidated; this parameter is ignored. |
---|
Reads at most length
bytes from this stream and stores them in
the byte array buffer
starting at offset
. Bytes are read
from the pushback buffer first, then from the source stream if more bytes
are required. Blocks until count
bytes have been read, the end of
the source stream is detected or an exception is thrown.
buffer | the array in which to store the bytes read from this stream. |
---|---|
offset | the initial position in buffer to store the bytes read
from this stream. |
length | the maximum number of bytes to store in buffer . |
IndexOutOfBoundsException | if offset < 0 or length < 0 , or if
offset + length is greater than the length of
buffer . |
---|---|
IOException | if this stream is closed or another I/O error occurs while reading from this stream. |
NullPointerException | if buffer is null .
|
Reads a single byte from this stream and returns it as an integer in the range from 0 to 255. If the pushback buffer does not contain any available bytes then a byte from the source input stream is returned. Blocks until one byte has been read, the end of the source stream is detected or an exception is thrown.
IOException | if this stream is closed or an I/O error occurs while reading from this stream. |
---|
Resets this stream to the last marked position. Resetting the stream is
not supported in this class; this implementation always throws an
IOException
.
IOException | if this method is called. |
---|
Skips count
bytes in this stream. This implementation skips bytes
in the pushback buffer first and then in the source stream if necessary.
count | the number of bytes to skip. |
---|
IOException | if this stream is closed or another I/O error occurs. |
---|
Pushes all the bytes in buffer
back to this stream. The bytes are
pushed back in such a way that the next byte read from this stream is
buffer[0], then buffer[1] and so on.
If this stream'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 bytes to push back to this stream. |
---|
IOException | if the free space in the internal pushback buffer is not
sufficient to store the contents of buffer .
|
---|
Pushes a subset of the bytes in buffer
back to this stream. The
subset is defined by the start position offset
within
buffer
and the number of bytes 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 bytes to push back to this stream. |
---|---|
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 length < 0 , or if
offset + length is greater than the length of
buffer . |
---|---|
IOException | if the free space in the internal pushback buffer is not
sufficient to store the selected contents of buffer .
|
Pushes the specified byte oneByte
back to this stream. Only the
least significant byte of the integer oneByte
is pushed back.
This is done in such a way that the next byte read from this stream is
(byte) oneByte
.
If this stream's internal pushback buffer cannot store the byte, an
IOException
is thrown.
oneByte | the byte to push back to this stream. |
---|
IOException | if this stream is closed or the internal pushback buffer is full. |
---|