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.
Definition at line 87 of file ThresholdingOutputStream.java.
Public Member Functions | |
ThresholdingOutputStream (int threshold) | |
Constructs an instance of this class which will trigger an event at the specified threshold. | |
void | write (int b) throws IOException |
Writes the specified byte to this output stream. | |
void | write (byte b[]) throws IOException |
Writes b.length bytes from the specified byte array to this output stream. | |
void | write (byte b[], int off, int len) throws IOException |
Writes len bytes from the specified byte array starting at offset off to this output stream. | |
void | flush () throws IOException |
Flushes this output stream and forces any buffered output bytes to be written out. | |
void | close () throws IOException |
Closes this output stream and releases any system resources associated with this stream. | |
int | getThreshold () |
Returns the threshold, in bytes, at which an event will be triggered. | |
long | getByteCount () |
Returns the number of bytes that have been written to this output stream. | |
boolean | isThresholdExceeded () |
Determines whether or not the configured threshold has been exceeded for this output stream. | |
Protected Member Functions | |
void | checkThreshold (int count) throws IOException |
Checks to see if writing the specified number of bytes would cause the configured threshold to be exceeded. | |
abstract OutputStream | getStream () throws IOException |
Returns the underlying output stream, to which the corresponding OutputStream methods in this class will ultimately delegate. | |
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. |
org.apache.commons.fileupload.ThresholdingOutputStream.ThresholdingOutputStream | ( | int | threshold | ) |
Constructs an instance of this class which will trigger an event at the specified threshold.
threshold | The number of bytes at which to trigger an event. |
Definition at line 121 of file ThresholdingOutputStream.java.
void org.apache.commons.fileupload.ThresholdingOutputStream.write | ( | int | b | ) | throws IOException |
Writes the specified byte to this output stream.
b | The byte to be written. |
IOException | if an error occurs. |
Definition at line 137 of file ThresholdingOutputStream.java.
References org.apache.commons.fileupload.ThresholdingOutputStream.checkThreshold(), and org.apache.commons.fileupload.ThresholdingOutputStream.getStream().
void org.apache.commons.fileupload.ThresholdingOutputStream.write | ( | byte | b[] | ) | throws IOException |
Writes b.length
bytes from the specified byte array to this output stream.
b | The array of bytes to be written. |
IOException | if an error occurs. |
Definition at line 153 of file ThresholdingOutputStream.java.
References org.apache.commons.fileupload.ThresholdingOutputStream.checkThreshold(), and org.apache.commons.fileupload.ThresholdingOutputStream.getStream().
void org.apache.commons.fileupload.ThresholdingOutputStream.write | ( | byte | b[], | |
int | off, | |||
int | len | |||
) | throws IOException |
Writes len
bytes from the specified byte array starting at offset off
to this output stream.
b | The byte array from which the data will be written. | |
off | The start offset in the byte array. | |
len | The number of bytes to write. |
IOException | if an error occurs. |
Definition at line 171 of file ThresholdingOutputStream.java.
References org.apache.commons.fileupload.ThresholdingOutputStream.checkThreshold(), and org.apache.commons.fileupload.ThresholdingOutputStream.getStream().
void org.apache.commons.fileupload.ThresholdingOutputStream.flush | ( | ) | throws IOException |
Flushes this output stream and forces any buffered output bytes to be written out.
IOException | if an error occurs. |
Definition at line 185 of file ThresholdingOutputStream.java.
References org.apache.commons.fileupload.ThresholdingOutputStream.getStream().
Referenced by org.apache.commons.fileupload.ThresholdingOutputStream.close().
void org.apache.commons.fileupload.ThresholdingOutputStream.close | ( | ) | throws IOException |
Closes this output stream and releases any system resources associated with this stream.
IOException | if an error occurs. |
Definition at line 197 of file ThresholdingOutputStream.java.
References org.apache.commons.fileupload.ThresholdingOutputStream.flush(), and org.apache.commons.fileupload.ThresholdingOutputStream.getStream().
int org.apache.commons.fileupload.ThresholdingOutputStream.getThreshold | ( | ) |
Returns the threshold, in bytes, at which an event will be triggered.
Definition at line 219 of file ThresholdingOutputStream.java.
long org.apache.commons.fileupload.ThresholdingOutputStream.getByteCount | ( | ) |
Returns the number of bytes that have been written to this output stream.
Definition at line 230 of file ThresholdingOutputStream.java.
boolean org.apache.commons.fileupload.ThresholdingOutputStream.isThresholdExceeded | ( | ) |
Determines whether or not the configured threshold has been exceeded for this output stream.
true
if the threshold has been reached; false
otherwise. Definition at line 243 of file ThresholdingOutputStream.java.
Referenced by org.apache.commons.fileupload.DeferredFileOutputStream.isInMemory().
void org.apache.commons.fileupload.ThresholdingOutputStream.checkThreshold | ( | int | count | ) | throws IOException [protected] |
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.
count | The number of bytes about to be written to the underlying output stream. |
IOException | if an error occurs. |
Definition at line 262 of file ThresholdingOutputStream.java.
References org.apache.commons.fileupload.ThresholdingOutputStream.thresholdReached().
Referenced by org.apache.commons.fileupload.ThresholdingOutputStream.write().
abstract OutputStream org.apache.commons.fileupload.ThresholdingOutputStream.getStream | ( | ) | throws IOException [protected, pure virtual] |
Returns the underlying output stream, to which the corresponding OutputStream
methods in this class will ultimately delegate.
IOException | if an error occurs. |
Implemented in org.apache.commons.fileupload.DeferredFileOutputStream.
Referenced by org.apache.commons.fileupload.ThresholdingOutputStream.close(), org.apache.commons.fileupload.ThresholdingOutputStream.flush(), and org.apache.commons.fileupload.ThresholdingOutputStream.write().
abstract void org.apache.commons.fileupload.ThresholdingOutputStream.thresholdReached | ( | ) | throws IOException [protected, pure virtual] |
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.
IOException | if an error occurs. |
Implemented in org.apache.commons.fileupload.DeferredFileOutputStream.
Referenced by org.apache.commons.fileupload.ThresholdingOutputStream.checkThreshold().