Top Description Fields Constructors Methods
org.apache.commons.io.input

public abstract Class ProxyInputStream

extends FilterInputStream
Class Inheritance
Known Direct Subclasses
org.apache.commons.io.input.SwappedDataInputStream, org.apache.commons.io.input.CountingInputStream
Imports
java.io.FilterInputStream, .IOException, .InputStream

A Proxy stream which acts as expected, that is it passes the method calls on to the proxied stream and doesn't change which methods are being called.

It is an alternative base class to FilterInputStream to increase reusability, because FilterInputStream changes the methods being called, such as read(byte[]) to read(byte[], int, int).

Author
Stephen Colebourne
Version
$Id: ProxyInputStream.java 471628 2006-11-06 04:06:45Z bayard $

Field Summary

Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
ProxyInputStream(InputStream
the InputStream to delegate to
proxy
)

Constructs a new ProxyInputStream.

Method Summary

Modifier and TypeMethod and Description
public int
available()

Overrides java.io.FilterInputStream.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.FilterInputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.
public synchronized void
mark(int
the maximum limit of bytes that can be read before the mark position becomes invalid.
idx
)

Overrides java.io.FilterInputStream.mark.

Marks the current position in this input stream.
public boolean
markSupported()

Overrides java.io.FilterInputStream.markSupported.

Tests if this input stream supports the mark and reset methods.
public int
read()

Overrides java.io.FilterInputStream.read.

Reads the next byte of data from the input stream.
public int
read(byte[]
the buffer into which the data is read.
bts
)

Overrides java.io.FilterInputStream.read.

Reads up to b.length bytes of data from this input stream into an array of bytes.
public int
read(byte[]
the buffer into which the data is read.
bts
,
int
the start offset in array b at which the data is written.
st
,
int
the maximum number of bytes to read.
end
)

Overrides java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes.
public synchronized void
reset()

Overrides java.io.FilterInputStream.reset.

Repositions this stream to the position at the time the mark method was last called on this input stream.
public long
skip(long
the number of bytes to be skipped.
ln
)

Overrides java.io.FilterInputStream.skip.

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

Constructor Detail

ProxyInputStreamback to summary
public ProxyInputStream(InputStream proxy)

Constructs a new ProxyInputStream.

Parameters
proxy:InputStream

the InputStream to delegate to

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.FilterInputStream.available.

Doc from java.io.FilterInputStream.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.

Returns:int

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

Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.InputStream#available()
closeback to summary
public void close() throws IOException

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.FilterInputStream.close.

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

Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.InputStream#close()
markback to summary
public synchronized void mark(int idx)

Overrides java.io.FilterInputStream.mark.

Doc from java.io.FilterInputStream.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.

Parameters
idx:int

the maximum limit of bytes that can be read before the mark position becomes invalid.

See Also
java.io.InputStream#mark(int)
markSupportedback to summary
public boolean markSupported()

Overrides java.io.FilterInputStream.markSupported.

Doc from java.io.FilterInputStream.markSupported.

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

Returns:boolean

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

See Also
java.io.InputStream#markSupported()
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.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.

Returns:int

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

Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.InputStream#read()
readback to summary
public int read(byte[] bts) throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.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.

Parameters
bts:byte[]

the buffer into which the data is read.

Returns:int

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.

Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.InputStream#read(byte[])
readback to summary
public int read(byte[] bts, int st, int end) throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.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.

Parameters
bts:byte[]

the buffer into which the data is read.

st:int

the start offset in array b at which the data is written.

end:int

the maximum number of bytes to read.

Returns:int

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.

Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.InputStream#read(byte[], int, int)
resetback to summary
public synchronized void reset() throws IOException

Overrides java.io.FilterInputStream.reset.

Doc from java.io.FilterInputStream.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.

Exceptions
IOException:
if this stream has not been marked or if the mark has been invalidated.
See Also
java.io.InputStream#reset()
skipback to summary
public long skip(long ln) throws IOException

Overrides java.io.FilterInputStream.skip.

Doc from java.io.FilterInputStream.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.

Parameters
ln:long

the number of bytes to be skipped.

Returns:long

the actual number of bytes skipped.

Exceptions
IOException:
if in.skip(n) throws an IOException.
See Also
java.io.InputStream#skip(long)