One of the new applications for caching is the implementation of the push back (pushback). The push-back is used for the input stream to allow the bytes to be read and then returned (pushed back) into the stream. The Pushbackinputstream class implements this idea and provides a mechanism for "peeping" from the contents of the input stream without destroying them.
The Pushbackinputstream class has the following constructors:
Pushbackinputstream (InputStream inputstream) pushbackinputstream (InputStream inputstream,int numBytes)
The first form creates a stream object that allows one byte to be returned to the input stream, and the second form creates a stream object with a numbytes-length push-back cache, allowing multiple bytes to be pushed back into the input stream.
In addition to the familiar approach from InputStream, the Pushbackinputstream class also provides the unread () method, as follows:
void unread (int b) void unread (byte[] buffer) void unread (byte[] buffer,int offset,int numbytes)
The first form pushes back the low byte of B, which causes subsequent read () calls to return to the next byte. The second form pushes back the bytes in buffer. The third form pushes back the NumBytes bytes in buffer starting with offset. When the rollback cache is full, an IOException exception is thrown if an attempt is made to push back the bytes.
Explore Java IO's Pushbackinputstream class