All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.io.PushbackInputStream

java.lang.Object
   |
   +----java.io.InputStream
           |
           +----java.io.FilterInputStream
                   |
                   +----java.io.PushbackInputStream

public class PushbackInputStream
extends FilterInputStream
This class is an input stream filter that provides a 1-byte pushback buffer. This feature allows an application to "unread" the last character that it read. The next time that a read is performed on the input stream filter, the "unread" character is re-read.

This functionality is useful when a fragment of code should read an indefinite number of data bytes that 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 re-read the byte that was pushed back.


Variable Index

 o buf
The push back buffer.
 o pos
The current position within the buffer.

Constructor Index

 o PushbackInputStream(InputStream)
Constructs a new pushback input stream that reads its input from the specified input stream.
 o PushbackInputStream(InputStream, int)
Creates a new input stream with a push back buffer of specified size.

Method Index

 o available()
Returns the number of bytes that can be read from this input stream without blocking.
 o markSupported()
Tests if the input stream supports the mark and reset methods.
 o read()
Reads the next byte of data from this input stream.
 o read(byte[], int, int)
Reads up to len bytes of data from this input stream into an array of bytes.
 o unread(byte[])
Pushes back an array of bytes.
 o unread(byte[], int, int)
Pushes back an array of bytes.
 o unread(int)
Pushes back a character so that it is read again by the next call to the read method on this input stream.

Variables

 o buf
 protected byte buf[]
The push back buffer.

 o pos
 protected int pos
The current position within the buffer.

Constructors

 o PushbackInputStream
 public PushbackInputStream(InputStream in,
                            int size)
Creates a new input stream with a push back buffer of specified size.

Parameters:
size - the size of the push back buffer
 o PushbackInputStream
 public PushbackInputStream(InputStream in)
Constructs a new pushback input stream that reads its input from the specified input stream.

Parameters:
in - the underlying input stream.

Methods

 o read
 public int read() throws IOException
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

The read method of PushbackInputStream returns the just pushed-back character, if there is one, and otherwise calls the read method of its underlying input stream and returns whatever value that method returns.

Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws: IOException
if an I/O error occurs.
Overrides:
read in class FilterInputStream
See Also:
read
 o read
 public int read(byte b[],
                 int off,
                 int len) throws IOException
Reads up to len bytes of data from this input stream into an array of bytes. This method blocks until at least 1 byte of input is available.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws: IOException
if an I/O error occurs.
Overrides:
read in class FilterInputStream
 o unread
 public void unread(int b) throws IOException
Pushes back a character so that it is read again by the next call to the read method on this input stream.

Parameters:
b - the character to push back.
Throws: IOException
if the application attempts to push back a character before the previously pushed-back character has been read.
 o unread
 public void unread(byte b[],
                    int off,
                    int len) throws IOException
Pushes back an array of bytes.

Parameters:
b - the bytes to push back
off - the start offset of the data
len - the number of bytes to push back.
Throws: IOException
If there is not enough room in the push back buffer for the specified number of bytes.
 o unread
 public void unread(byte b[]) throws IOException
Pushes back an array of bytes.

Parameters:
b - the bytes to push back
Throws: IOException
If there is not enough room in the push back buffer for the specified number of bytes.
 o available
 public int available() throws IOException
Returns the number of bytes that can be read from this input stream without blocking.

The available method of PushbackInputStream calls the available method of its underlying input stream; it returns that value if there is no character that has been pushed back, or that value plus 1 if there is a character that has been pushed back.

Returns:
the number of bytes that can be read from the input stream without blocking.
Throws: IOException
if an I/O error occurs.
Overrides:
available in class FilterInputStream
See Also:
in
 o markSupported
 public boolean markSupported()
Tests if the input stream supports the mark and reset methods. The markSupported method of PushbackInputStream always returns false.

Returns:
true if this stream type supports the mark and reset methods; false otherwise.
Overrides:
markSupported in class FilterInputStream
See Also:
mark, reset

All Packages  Class Hierarchy  This Package  Previous  Next  Index