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

public abstract Class ThresholdingOutputStream

extends OutputStream
Class Inheritance
Known Direct Subclasses
org.apache.tomcat.util.http.fileupload.DeferredFileOutputStream
Imports
java.io.IOException, .OutputStream

An output stream which triggers an event when a specified number of bytes of data have been written to it. The event can be used, for example, to throw an exception if a maximum has been reached, or to switch the underlying stream type when the threshold is exceeded.

This class overrides all OutputStream methods. However, these overrides ultimately call the corresponding methods in the underlying output stream implementation.

Note

This implementation may trigger the event before the threshold is actually reached, since it triggers when a pending write operation would cause the threshold to be exceeded.

Field Summary

Modifier and TypeField and Description
private final int
threshold

The threshold at which the event will be triggered.

private boolean
thresholdExceeded

Whether or not the configured threshold has been exceeded.

private long
written

The number of bytes written to the output stream.

Constructor Summary

AccessConstructor and Description
public
ThresholdingOutputStream(final int
The number of bytes at which to trigger an event.
threshold
)

Constructs an instance of this class which will trigger an event at the specified threshold.

Method Summary

Modifier and TypeMethod and Description
protected void
checkThreshold(final int
The number of bytes about to be written to the underlying output stream.
count
)

Checks to see if writing the specified number of bytes would cause the configured threshold to be exceeded.

public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.

protected abstract OutputStream

Returns:

The underlying output stream.
getStream
()

Returns the underlying output stream, to which the corresponding OutputStream methods in this class will ultimately delegate.

public boolean

Returns:

true if the threshold has been reached; false otherwise.
isThresholdExceeded
()

Determines whether or not the configured threshold has been exceeded for this output stream.

protected abstract void
thresholdReached()

Indicates that the configured threshold has been reached, and that a subclass should take whatever action necessary on this event.

public void
write(final int
The byte to be written.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(final byte[]
The array of bytes to be written.
b
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.

public void
write(final byte[]
The byte array from which the data will be written.
b
,
final int
The start offset in the byte array.
off
,
final int
The number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Inherited from java.io.OutputStream:
nullOutputStream

Field Detail

thresholdback to summary
private final int threshold

The threshold at which the event will be triggered.

thresholdExceededback to summary
private boolean thresholdExceeded

Whether or not the configured threshold has been exceeded.

writtenback to summary
private long written

The number of bytes written to the output stream.

Constructor Detail

ThresholdingOutputStreamback to summary
public ThresholdingOutputStream(final int threshold)

Constructs an instance of this class which will trigger an event at the specified threshold.

Parameters
threshold:int

The number of bytes at which to trigger an event.

Method Detail

checkThresholdback to summary
protected void checkThreshold(final int count) throws IOException

Checks to see if writing the specified number of bytes would cause the configured threshold to be exceeded. If so, triggers an event to allow a concrete implementation to take action on this.

Parameters
count:int

The number of bytes about to be written to the underlying output stream.

Exceptions
IOException:
if an error occurs.
closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

Annotations
@Override
Exceptions
IOException:
if an error occurs.
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.

Annotations
@Override
Exceptions
IOException:
if an error occurs.
getStreamback to summary
protected abstract OutputStream getStream() throws IOException

Returns the underlying output stream, to which the corresponding OutputStream methods in this class will ultimately delegate.

Returns:OutputStream

The underlying output stream.

Exceptions
IOException:
if an error occurs.
isThresholdExceededback to summary
public boolean isThresholdExceeded()

Determines whether or not the configured threshold has been exceeded for this output stream.

Returns:boolean

true if the threshold has been reached; false otherwise.

thresholdReachedback to summary
protected abstract void thresholdReached() throws IOException

Indicates that the configured threshold has been reached, and that a subclass should take whatever action necessary on this event. This may include changing the underlying output stream.

Exceptions
IOException:
if an error occurs.
writeback to summary
public void write(final int b) throws IOException

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

Parameters
b:int

The byte to be written.

Annotations
@Override
Exceptions
IOException:
if an error occurs.
writeback to summary
public void write(final byte[] b) throws IOException

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.

Parameters
b:byte[]

The array of bytes to be written.

Annotations
@Override
Exceptions
IOException:
if an error occurs.
writeback to summary
public void write(final byte[] b, final int off, final int len) throws IOException

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Parameters
b:byte[]

The byte array from which the data will be written.

off:int

The start offset in the byte array.

len:int

The number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an error occurs.