APIdia Launch Partner
Top Description Fields Constructors Methods
java.io

public Class FilterInputStream

extends InputStream
Class Inheritance
Known Direct Subclasses
java.io.LineNumberInputStream, java.io.PushbackInputStream, java.security.DigestInputStream, java.util.jar.Manifest.FastInputStream, java.util.zip.CheckedInputStream, java.util.zip.DeflaterInputStream, java.util.zip.InflaterInputStream, javax.crypto.CipherInputStream, sun.net.TelnetInputStream, sun.net.www.MeteredStream, sun.net.www.protocol.http.HttpURLConnection.HttpInputStream, sun.security.provider.FileInputStreamPool.UnclosableInputStream, sun.security.provider.certpath.URICertStore.SizeLimitedInputStream, sun.net.www.content.text.PlainTextInputStream, sun.net.www.http.HttpCaptureInputStream, sun.net.www.protocol.ftp.FtpURLConnection.FtpInputStream, sun.net.www.protocol.jar.JarURLConnection.JarURLInputStream, java.io.BufferedInputStream, java.io.DataInputStream

A FilterInputStream wraps some other input stream, which it uses as its basic source of data, possibly transforming the data along the way or providing additional functionality. The class FilterInputStream itself simply overrides select methods of InputStream with versions that pass all requests to the wrapped input stream. Subclasses of FilterInputStream may of course override any methods declared or inherited by FilterInputStream, and may also provide additional fields and methods.
Author
Jonathan Payne
Since
1.0

Field Summary

Modifier and TypeField and Description
protected volatile InputStream
in

The input stream to be filtered.

Constructor Summary

AccessConstructor and Description
protected
FilterInputStream(InputStream
the underlying input stream, or null if this instance is to be created without an underlying stream.
in
)

Creates a FilterInputStream by assigning the argument in to the field this.in so as to remember it for later use.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.
available
()

Overrides java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.

public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

public void
mark(int readlimit)

Overrides java.io.InputStream.mark.

Marks the current position in this input stream.

public boolean

Returns:

true if this stream type supports the mark and reset method; false otherwise.
markSupported
()

Overrides java.io.InputStream.markSupported.

Tests if this input stream supports the mark and reset methods.

public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[] b)

Overrides java.io.InputStream.read.

Reads up to b.length bytes of data from this input stream into an array of bytes.

public int
read(byte[] b, int off, int len)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes.

public void
reset()

Overrides java.io.InputStream.reset.

Repositions this stream to the position at the time the mark method was last called on this input stream.

public long

Returns:

the actual number of bytes skipped.
skip
(long n)

Overrides java.io.InputStream.skip.

Skips over and discards n bytes of data from the input stream.

Inherited from java.io.InputStream:
nullInputStreamreadAllBytesreadNBytesreadNBytesskipNBytestransferTo

Field Detail

inback to summary
protected volatile InputStream in

The input stream to be filtered.

Constructor Detail

FilterInputStreamback to summary
protected FilterInputStream(InputStream in)

Creates a FilterInputStream by assigning the argument in to the field this.in so as to remember it for later use.

Parameters
in:InputStream

the underlying input stream, or null if this instance is to be created without an underlying stream.

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Implementation Specification

This method returns the result of in.available().

Returns:int

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Implementation Specification

This method simply performs in.close().

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.FilterInputStream#in
markback to summary
public void mark(int readlimit)

Overrides java.io.InputStream.mark.

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.

Implementation Specification

This method simply performs in.mark(readlimit).

Annotations
@Override
See Also
java.io.FilterInputStream#in, java.io.FilterInputStream#reset()
markSupportedback to summary
public boolean markSupported()

Overrides java.io.InputStream.markSupported.

Tests if this input stream supports the mark and reset methods.

Implementation Specification

This method simply performs in.markSupported().

Returns:boolean

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

Annotations
@Override
See Also
java.io.FilterInputStream#in, java.io.InputStream#mark(int), java.io.InputStream#reset()
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the 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.

Implementation Specification

This method simply performs in.read() and returns the result.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.FilterInputStream#in
readback to summary
public int read(byte[] b) throws IOException

Overrides java.io.InputStream.read.

Reads up to b.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

Implementation Specification

This method simply performs the call read(b, 0, b.length) and returns the result. It is important that it does not do in.read(b) instead; certain subclasses of FilterInputStream depend on the implementation strategy actually used.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.FilterInputStream#read(byte[], int, int)
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.InputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

Implementation Specification

This method simply performs in.read(b, off, len) and returns the result.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
NullPointerException:
If b is null.
IndexOutOfBoundsException:
If off is negative, len is negative, or len is greater than b.length - off
See Also
java.io.FilterInputStream#in
resetback to summary
public void reset() throws IOException

Overrides java.io.InputStream.reset.

Repositions this stream to the position at the time the mark method was last called on this 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.

Implementation Specification

This method simply performs in.reset().

Annotations
@Override
Exceptions
IOException:
if this stream has not been marked or if the mark has been invalidated.
See Also
java.io.FilterInputStream#in, java.io.FilterInputStream#mark(int)
skipback to summary
public long skip(long n) throws IOException

Overrides java.io.InputStream.skip.

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.

Implementation Specification

This method simply performs in.skip(n) and returns the result.

Returns:long

the actual number of bytes skipped.

Annotations
@Override
Exceptions
IOException:
if in.skip(n) throws an IOException.