Top Description Fields Constructors Methods
org.apache.derby.iapi.services.io

public Class LimitInputStream

extends FilterInputStream
implements Limit
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.services.io.Limit
Known Direct Subclasses
org.apache.derby.iapi.types.RawToBinaryFormatStream
Imports
java.io.InputStream, .FilterInputStream, .IOException

An abstract InputStream that provides abstract methods to limit the range that can be read from the stream.

Field Summary

Modifier and TypeField and Description
protected boolean
protected int
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
LimitInputStream(InputStream
InputStream to wrap
in
)

Construct a LimitInputStream and call the clearLimit() method.

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 int

Returns:

the number of bytes within the limit that have not been read. -1 if no limit was set.
clearLimit
()

Implements org.apache.derby.iapi.services.io.Limit.clearLimit.

Clear any limit set by setLimit.

public boolean

Returns:

false
markSupported
()

Overrides java.io.FilterInputStream.markSupported.

This stream doesn't support mark/reset, independent of whether the underlying stream does so or not.

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.
b
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.FilterInputStream.read.

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

public void
public void
setLimit(int
The length to set
length
)

Implements org.apache.derby.iapi.services.io.Limit.setLimit.

Set the limit of the stream that can be read.

public long
skip(long
the number of bytes to be skipped.
count
)

Overrides java.io.FilterInputStream.skip.

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

Inherited from java.io.FilterInputStream:
closemarkreadreset

Field Detail

limitInPlaceback to summary
protected boolean limitInPlace
remainingBytesback to summary
protected int remainingBytes

Constructor Detail

LimitInputStreamback to summary
public LimitInputStream(InputStream in)

Construct a LimitInputStream and call the clearLimit() method.

Parameters
in:InputStream

InputStream to wrap

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.
clearLimitback to summary
public int clearLimit()

Implements org.apache.derby.iapi.services.io.Limit.clearLimit.

Clear any limit set by setLimit. After this call no limit checking will be made on any read until a setLimit()) call is made.

Returns:int

the number of bytes within the limit that have not been read. -1 if no limit was set.

markSupportedback to summary
public boolean markSupported()

Overrides java.io.FilterInputStream.markSupported.

This stream doesn't support mark/reset, independent of whether the underlying stream does so or not.

The reason for not supporting mark/reset, is that it is hard to combine with the limit functionality without always keeping track of the number of bytes read.

Returns:boolean

false

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.
readback to summary
public int read(byte[] b, int off, int len) 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
b:byte[]

the buffer into which the data is read.

off:int

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

len: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.
setInputback to summary
public void setInput(InputStream in)
setLimitback to summary
public void setLimit(int length)

Implements org.apache.derby.iapi.services.io.Limit.setLimit.

Set the limit of the stream that can be read. After this call up to and including length bytes can be read from or skipped in the stream. Any attempt to read more than length bytes will result in an EOFException

Parameters
length:int

Doc from org.apache.derby.iapi.services.io.Limit.setLimit.

The length to set

skipback to summary
public long skip(long count) 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
count: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.