Top Description Fields Constructors Methods
org.apache.tomcat.util.http.fileupload.util

public abstract Class LimitedInputStream

extends FilterInputStream
implements Closeable
Class Inheritance
All Implemented Interfaces
org.apache.tomcat.util.http.fileupload.util.Closeable
Imports
java.io.FilterInputStream, .IOException, .InputStream

An input stream, which limits its data size. This stream is used, if the content length is unknown.

Field Summary

Modifier and TypeField and Description
private boolean
closed

Whether this stream is already closed.

private long
count

The current number of bytes.

private final long
sizeMax

The maximum size of an item, in bytes.

Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
LimitedInputStream(final InputStream
The input stream, which shall be limited.
inputStream
,
final long
The limit; no more than this number of bytes shall be returned by the source stream.
pSizeMax
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
private void
checkLimit()

Called to check, whether the input streams limit is reached.

public void
close()

Overrides java.io.FilterInputStream.close.

Implements org.apache.tomcat.util.http.fileupload.util.Closeable.close, java.io.Closeable.close.

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

public boolean

Returns:

True, if the stream is closed, otherwise false.
isClosed
()

Implements org.apache.tomcat.util.http.fileupload.util.Closeable.isClosed.

Returns, whether this stream is already closed.

protected abstract void
raiseError(long
The input streams limit, in bytes.
pSizeMax
,
long
The actual number of bytes.
pCount
)

Called to indicate, that the input streams limit has been exceeded.

public int

Returns:

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

Overrides java.io.FilterInputStream.read.

Reads the next byte of data from this input stream.

public int

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.
read
(final byte[]
the buffer into which the data is read.
b
,
final int
The start offset in the destination array b.
off
,
final int
the maximum number of bytes read.
len
)

Overrides java.io.FilterInputStream.read.

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

Inherited from java.io.FilterInputStream:
availablemarkmarkSupportedreadresetskip

Field Detail

closedback to summary
private boolean closed

Whether this stream is already closed.

countback to summary
private long count

The current number of bytes.

sizeMaxback to summary
private final long sizeMax

The maximum size of an item, in bytes.

Constructor Detail

LimitedInputStreamback to summary
public LimitedInputStream(final InputStream inputStream, final long pSizeMax)

Creates a new instance.

Parameters
inputStream:InputStream

The input stream, which shall be limited.

pSizeMax:long

The limit; no more than this number of bytes shall be returned by the source stream.

Method Detail

checkLimitback to summary
private void checkLimit() throws IOException

Called to check, whether the input streams limit is reached.

Exceptions
IOException:
The given limit is exceeded.
closeback to summary
public void close() throws IOException

Overrides java.io.FilterInputStream.close.

Implements org.apache.tomcat.util.http.fileupload.util.Closeable.close, java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream. This method simply performs in.close().

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.FilterInputStream#in
isClosedback to summary
public boolean isClosed() throws IOException

Implements org.apache.tomcat.util.http.fileupload.util.Closeable.isClosed.

Returns, whether this stream is already closed.

Returns:boolean

True, if the stream is closed, otherwise false.

Annotations
@Override
Exceptions
IOException:
An I/O error occurred.
raiseErrorback to summary
protected abstract void raiseError(long pSizeMax, long pCount) throws IOException

Called to indicate, that the input streams limit has been exceeded.

Parameters
pSizeMax:long

The input streams limit, in bytes.

pCount:long

The actual number of bytes.

Exceptions
IOException:
The called method is expected to raise an IOException.
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

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 simply performs in.read() and returns the result.

Returns:int

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

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

Overrides 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.

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

Parameters
b:byte[]

the buffer into which the data is read.

off:int

The start offset in the destination array b.

len:int

the maximum number of bytes 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.

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