java.lang.Object | +--java.io.InputStream | +--java.io.FilterInputStream | +--java.io.PushbackInputStream
byte[] | buf This is the buffer that is used to store the pushed back data |
int | pos This is the position in the buffer from which the next byte will be read. |
PushbackInputStream(java.io.InputStream in) This method initializes a |
PushbackInputStream(java.io.InputStream in, int size) This method initializes a |
int | available() This method returns the number of bytes that can be read from this stream before a read can block. |
synchronized void | close() This method closes the stream and releases any associated resources. |
boolean | markSupported() This method returns |
synchronized int | read() This method reads an unsigned byte from the input stream and returns it as an int in the range of 0-255. |
synchronized int | read(byte[] b, int off, int len) This method read bytes from a stream and stores them into a caller supplied buffer. |
void | reset() This method always throws an IOException in this class because mark/reset functionality is not supported. |
synchronized long | skip(long n) This method skips the specified number of bytes in the stream. |
synchronized void | unread(int b) This method pushes a single byte of data into the pushback buffer. |
synchronized void | unread(byte[] b) This method pushes all of the bytes in the passed byte array into the pushback bfer. |
synchronized void | unread(byte[] b, int off, int len) This method pushed back bytes from the passed in array into the pushback buffer. |
protected byte[] buf
protected int pos
buf[buf.length - 1]
to buf[0]
. Thus when
pos
is 0 the buffer is full and buf.length
when
it is empty
public PushbackInputStream(java.io.InputStream in)
PushbackInputStream
to
read from the * specified subordinate InputStream
with a default pushback buffer * size of 1.
in
- The subordinate stream to read frompublic PushbackInputStream(java.io.InputStream in, int size)
PushbackInputStream
to
read from the specified subordinate InputStream
with
the specified buffer size
in
- The subordinate InputStream
to read fromsize
- The pushback buffer size to usepublic int available()
This method will return the number of bytes available from the pushback buffer plus the number of bytes available from the underlying stream.
IOException
- If an error occurspublic synchronized void close()
IOException
- If an error occurs.public boolean markSupported()
false
to indicate that it does
not support mark/reset functionality.
false
to indicate that
this class does not support mark/reset functionalitypublic synchronized int read()
This method will block until the byte can be read.
IOException
- If an error occurspublic synchronized int read(byte[] b, int off, int len)
offset
into the buffer and attempts to read
len
bytes. This method can return before reading the
number of bytes requested. The actual number of bytes 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 first reads bytes from the pushback buffer in order to satisfy the read request. If the pushback buffer cannot provide all of the bytes requested, the remaining bytes are read from the underlying stream.
b
- The array into which the bytes read should be storedoff
- The offset into the array to start storing byteslen
- The requested number of bytes to readIOException
- If an error occurs.public void reset()
IOException
- Always thrown for this classpublic synchronized long skip(long n)
This method first discards bytes from the buffer, then calls the
skip
method on the underlying InputStream
to
skip additional bytes if necessary.
n
- The requested number of bytes to skipIOException
- If an error occurspublic synchronized void unread(byte[] b)
b[0]
followed by b[1]
, etc.
If the pushback buffer cannot hold all of the requested bytes, an exception is thrown.
b
- The byte array to be pushed backIOException
- If the pushback buffer is fullpublic synchronized void unread(byte[] b, int off, int len)
b[offset]
to
b[offset]
followed by b[offset + 1]
,
etc.
If the pushback buffer cannot hold all of the requested bytes, an exception is thrown.
b
- The byte array to be pushed backoff
- The index into the array where the bytes to be push startlen
- The number of bytes to be pushed.IOException
- If the pushback buffer is fullpublic synchronized void unread(int b)
If the pushback buffer is full, this method throws an exception.
The argument to this method is an int
. Only the low
eight bits of this value are pushed back.
b
- The byte to be pushed back, passed as an intIOException
- If the pushback buffer is full.
FilterInputStream
provides the ability to unread data from a stream. It maintains an internal buffer of unread data that is supplied to the next read operation. This is conceptually similar to mark/reset functionality, except that in this case the position to reset the stream to does not need to be known in advance.The default pushback buffer size one byte, but this can be overridden by the creator of the stream.