is new.
java.lang.Objectjava.io.InputStream
java.io.FilterInputStream
java.io.PushbackInputStream
public class PushbackInputStream
A PushbackInputStream adds functionality to another input stream, namely the ability to "push back" or "unread" one byte. This is useful in situations where it is convenient for a fragment of code to read an indefinite number of data bytes that are delimited by a particular byte value; after reading the terminating byte, the code fragment can "unread" it, so that the next read operation on the input stream will reread the byte that was pushed back. For example, bytes representing the characters constituting an identifier might be terminated by a byte representing an operator character; a method whose job is to read just an identifier can read until it sees the operator and then push the operator back to be re-read.
| Field Summary | |
|---|---|
| protected byte[] |
buf
The pushback buffer. |
| protected int |
pos
The position within the pushback buffer from which the next byte will be read. |
| Fields inherited from class java.io. FilterInputStream |
|---|
| in |
| Constructor Summary | |
|---|---|
|
PushbackInputStream
(
InputStream
in) Creates a PushbackInputStream and saves its argument, the input stream in, for later use. |
|
|
PushbackInputStream
(
InputStream
in, int size) Creates a PushbackInputStream with a pushback buffer of the specified size, and saves its argument, the input stream in, for later use. |
|
| Method Summary | |
|---|---|
| int |
available
() Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. |
| void |
close
() Closes this input stream and releases any system resources associated with the stream. |
| void |
mark
(int readlimit) Marks the current position in this input stream. |
| boolean |
markSupported
() Tests if this input stream supports the mark and reset methods, which it does not. |
| int |
read
() Reads the next byte of data from this input stream. |
| int |
read
(byte[] b, int off, int len) Reads up to len bytes of data from this input stream into an array of bytes. |
| void |
reset
() Repositions this stream to the position at the time the mark method was last called on this input stream. |
| long |
skip
(long n) Skips over and discards n bytes of data from this input stream. |
| void |
unread
(byte[] b) Pushes back an array of bytes by copying it to the front of the pushback buffer. |
| void |
unread
(byte[] b, int off, int len) Pushes back a portion of an array of bytes by copying it to the front of the pushback buffer. |
| void |
unread
(int b) Pushes back a byte by copying it to the front of the pushback buffer. |
| Methods inherited from class java.io. FilterInputStream |
|---|
| read |
| Methods inherited from class java.lang. Object |
|---|
| clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
| Field Detail |
|---|
protected byte[] buf
protected int pos
| Constructor Detail |
|---|
public PushbackInputStream(InputStream in,
int size)
public PushbackInputStream(InputStream in)
| Method Detail |
|---|
public int read()
throws IOException
This method returns the most recently pushed-back byte, if there is one, and otherwise calls the read method of its underlying input stream and returns whatever value that method returns.
- if this input stream has been closed by invoking its
close()
method, or an I/O error occurs.
public int read(byte[] b,
int off,
int len)
throws IOException
- if this input stream has been closed by invoking its
close()
method, or an I/O error occurs.
public void unread(int b)
throws IOException
byte, or this input stream has been closed by invoking its
close()
method.
public void unread(byte[] b,
int off,
int len)
throws IOException
bytes, or this input stream has been closed by invoking its
close()
method.
public void unread(byte[] b)
throws IOException
bytes, or this input stream has been closed by invoking its
close()
method.
public int available()
throws IOException
The method returns the sum of the number of bytes that have been pushed back and the value returned by available .
invoking its
close()
method,
public long skip(long n)
throws IOException
The skip method of PushbackInputStream first skips over the bytes in the pushback buffer, if any. It then calls the skip method of the underlying input stream if more bytes need to be skipped. The actual number of bytes skipped is returned.
- if the stream does not support seek, or the stream has been closed by invoking its
close()
method, or an I/O error occurs.
public boolean markSupported()
public void mark(int readlimit)
The mark method of PushbackInputStream does nothing.
public void reset()
throws IOException
The method reset for class PushbackInputStream does nothing except throw an IOException.
public void close()
throws IOException
Once the stream has been closed, further read(), unread(), available(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.