All About PushbackInputStream in Java

0
32
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

PushbackInputStream in Java
PushbackInputStream in Java

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 constructor accepts InputStream as an argument . This class is generally used for Scanner for a compiler.

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.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

LEAVE A REPLY

Please enter your comment!
Please enter your name here