Package java.io Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class PushbackInputStream

Fields , Constructors , Methods

public  class  java.io.PushbackInputStream
    extends  java.io.FilterInputStream  
{
        // Fields
    protected int pushBack;	

        // Constructors
    public PushbackInputStream(InputStream  in);	

        // Methods
    public int available();	
    public boolean markSupported();	
    public int read();	
    public int read(byte  bytes[], int  offset, int length);	
    public void unread(int  ch);	
}

This class is an input stream filter that provides a one-byte push back 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 in situations where it is useful for a fragment of code to 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.


Fields


pushBack

protected int pushBack 

A character that has been "unread" and that will be the next byte read. The value -1 indicates no character in the buffer.


Constructors


PushbackInputStream

public PushbackInputStream(InputStream  in) 

Constructs a new pushback input stream that reads its input from the specified input stream.

ParameterDescription
in the underlying input stream


Methods


available

public int available() 
throws IOException 

Determines 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 one if there is a character that has been pushed back.

Return Value:

Returns the number of bytes that can be read from the input stream without blocking.

Overrides:

available in class FilterInputStream .

Throw:

IOException

If an I/O error occurs.


markSupported

public boolean markSupported() 

Determines if the input stream supports the mark and reset methods. The markSupported method of PushbackInputStream always returns false.

Return Value:

Returns true if this stream type supports the mark and and reset methods; false otherwise.

Overrides:

markSupported in class FilterInputStream .


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 either 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 the read method of its underlying input stream and returns whatever value that method returns.

Return Value:

Returns the next byte of data, or -1 if the end of the stream is reached.

Throw:

IOException

If an I/O error occurs.

Overrides:

read in class FilterInputStream .


read

public int read(byte  bytes[], int  offset, int  length) 
throws IOException 

Reads up to len bytes of data from this input stream into an array of bytes. This method blocks until at least one byte of input is available.

Return Value:

Returns the total number of bytes read into the buffer, or -1 is there is no more data because the end of the stream has been reached.

ParameterDescription
b the buffer into which the data is read
off the start offset of the data
len the maximum number of bytes read

Throw:

IOException

If an I/O error occurs.

Overrides:

read in class FilterInputStream .


unread

public void unread(int  ch) 
throws IOException 

Pushes back a character so that it is read again by the next call to the read method on this input stream.

ParameterDescription
ch the character to push back.

Throw:

IOException

If the application attempts to push back a character before the previously pushed back character has been read.



Top© 1996 Sun Microsystems, Inc. All rights reserved.