All About PushbackInputStream in Java



PushbackInputStream class is an input stream filter that provides an one byte push back buffer.This feature allows an application to 'unread' the last character it read.The next time a read is performed on the input stream the 'unread' character is 'reread'. This functionality is useful in situation where a fragment of the code to read am indefinite number of data bytes. These data bytes are delimited by  particular byte values .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.

The class structure of PushbackInputStream is given as:

public class java.io.PushbackInputStream extends java.io.FilterInputStream{
//member element
protected int pushBack;
//A character 'unread' will be next byte read.The value-1 indicates nil character in the buffer.
//constructors
public PushbackInputStream(InputStream in)
//constructs a new PushbackInputStream object that reads input from the specified InputStream.
//methods:
public int read();
public int read(byte b[],int offSet,int length);
public void unread(int ch);
public int available();
public boolean markSupported();
}
 
In addition,all methods may throw an IOException if an IO error occurs apart from their regular Exceptions.
All About PushbackInputStream in Java All About PushbackInputStream in Java Reviewed by Animesh Chatterjee on October 11, 2018 Rating: 5

No comments:

Powered by Blogger.