Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Class java.io.FilterInputStream

java.lang.Object
    |
    +----java.io.InputStream
            |
            +----java.io.FilterInputStream
Subclasses:
BufferedInputStream, CheckedInputStream, DataInputStream, DigestInputStream, InflaterInputStream, LineNumberInputStream, ProgressMonitorInputStream, PushbackInputStream

public class FilterInputStream
extends InputStream
This class is the superclass of all classes that filter input streams. These streams sit on top of an already existing input stream (the underlying input stream), but provide additional functionality.

The class FilterInputStream itself simply overrides all methods of InputStream with versions that pass all requests to the underlying input stream. Subclasses of FilterInputStream may further override some of these methods as well as provide additional methods and fields.

Since:
JDK1.0

Field Summary
InputStream  in
The underlying input stream.
 

Constructor Summary
 FilterInputStream(InputStream in)
Creates an input stream filter built on top of the specified input stream.
 

Method Summary
int  available()
Returns the number of bytes that can be read from this input stream without blocking.
void  close()
Closes this input stream and releases any system resources associated with the stream.
void  mark(int readlimit)
Marks the current position in this input stream.
boolean  markSupported()
Tests if this input stream supports the mark and reset methods.
int  read()
Reads the next byte of data from this input stream.
int  read(byte[] b)
Reads up to byte.length bytes of data from this input stream into an array of bytes.
int  read(byte[] b, int off, int len)
Reads up to len bytes of data from this input stream into an array of bytes.
void  reset()
Repositions this stream to the position at the time the mark method was last called on this input stream.
long  skip(long n)
Skips over and discards n bytes of data from the input stream.
 
Methods inherited from class java.io.InputStream
 available, close, mark, markSupported, read, read, read, reset, skip
 
Methods inherited from class java.lang.Object
 clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

protected InputStream in
The underlying input stream.
Constructor Detail

FilterInputStream

protected FilterInputStream(InputStream in)
Creates an input stream filter built on top of the specified input stream.
Parameters:
in - the underlying input stream.
Method Detail

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 FilterInputStream 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 InputStream
See Also:
in

read

public int read(byte[] b) throws IOException
Reads up to byte.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

The read method of FilterInputStream calls the read method of three arguments with the arguments b, 0, and b.length, and returns whatever value that method returns.

Note that this method does not call the one-argument read method of its underlying stream with the single argument b. Subclasses of FilterInputStream do not need to override this method if they have overridden the three-argument read method.

Parameters:
b - the buffer into which the data is 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 InputStream
See Also:
read(byte[], int, int)

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 some input is available.

The read method of FilterInputStream calls the read method of its underlying input stream with the same arguments and returns whatever value that method returns.

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 InputStream
See Also:
in

skip

public long skip(long n) throws IOException
Skips over and discards n bytes of data from the input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

The skip method of FilterInputStream calls the skip method of its underlying input stream with the same argument, and returns whatever value that method does.

Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
IOException - if an I/O error occurs.
Overrides:
skip in class InputStream

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

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 InputStream
See Also:
in

close

public void close() throws IOException
Closes this input stream and releases any system resources associated with the stream. The close method of FilterInputStream calls the close method of its underlying input stream.
Throws:
IOException - if an I/O error occurs.
Overrides:
close in class InputStream
See Also:
in

mark

public void mark(int readlimit)
Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

The readlimit argument tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

The mark method of FilterInputStream calls the mark method of its underlying input stream with the readlimit argument.

Parameters:
readlimit - the maximum limit of bytes that can be read before the mark position becomes invalid.
Overrides:
mark in class InputStream
See Also:
in, reset()

reset

public void reset() throws IOException
Repositions this stream to the position at the time the mark method was last called on this input stream.

The reset method of FilterInputStream calls the reset method of its underlying input stream.

Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parse, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails. If this happens within readlimit bytes, it allows the outer code to reset the stream and try another parser.

Throws:
IOException - if the stream has not been marked or if the mark has been invalidated.
Overrides:
reset in class InputStream
See Also:
in, mark(int)

markSupported

public boolean markSupported()
Tests if this input stream supports the mark and reset methods. The markSupported method of FilterInputStream calls the markSupported method of its underlying input stream and returns whatever value that method returns.
Returns:
true if this stream type supports the mark and reset method; false otherwise.
Overrides:
markSupported in class InputStream
See Also:
in, mark(int), reset()

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.