Filter Streams   «Prev 

Java read() and available() Methods

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

public class PushbackInputStream extends FilterInputStream

Class InputStream

java.lang.Object
java.io.InputStream
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
AudioInputStream, ByteArrayInputStream, FileInputStream, FilterInputStream, InputStream, 
ObjectInputStream, PipedInputStream, SequenceInputStream, StringBufferInputStream

A PushbackInputStream adds functionality to another input stream, namely the ability to "push back" or "unread" one byte.
This is useful in situations where it is convenient for a fragment of code to read an indefinite number of data bytes that are delimited by a particular byte value; 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. For example, bytes representing the characters constituting an identifier might be terminated by a byte representing an operator character; a method whose job is to read just an identifier can read until it sees the operator and then push the operator back to be re-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. This method returns the most recently pushed-back byte, if there is one, and otherwise calls the read method of its underlying input stream and returns whatever value that method returns.
Overrides:read in class FilterInputStreamReturns:the next byte of data, or -1 if the end of the stream has been reached.
Throws:IOException if this input stream has been closed by invoking its close() method, or an I/O error occurs.