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.
| Modifier and Type | Field 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. |
| Access | Constructor 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. |
| Modifier and Type | Method 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. Implements java. Closes this output stream and releases any system resources associated with this stream. |
| public void | flush()
Overrides java. Implements java. Flushes this output stream and forces any buffered output bytes to be written out. |
| protected abstract OutputStream | Returns: The underlying output stream.Returns the underlying output stream, to which the corresponding
|
| public boolean | Returns: true if the threshold has been reached;
false otherwise.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. Writes the specified byte to this output stream. |
| public void | write(final byte[]
The array of bytes to be written. b)Overrides java. Writes |
| 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. Writes |
| threshold | back to summary |
|---|---|
| private final int threshold The threshold at which the event will be triggered. | |
| thresholdExceeded | back to summary |
|---|---|
| private boolean thresholdExceeded Whether or not the configured threshold has been exceeded. | |
| written | back to summary |
|---|---|
| private long written The number of bytes written to the output stream. | |
| ThresholdingOutputStream | back to summary |
|---|---|
| public ThresholdingOutputStream(final int threshold) Constructs an instance of this class which will trigger an event at the specified threshold.
| |
| checkThreshold | back 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.
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Closes this output stream and releases any system resources associated with this stream.
| |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Overrides java. Implements java. Flushes this output stream and forces any buffered output bytes to be written out.
| |
| getStream | back to summary |
|---|---|
| protected abstract OutputStream getStream() throws IOException Returns the underlying output stream, to which the corresponding
| |
| isThresholdExceeded | back to summary |
|---|---|
| public boolean isThresholdExceeded() Determines whether or not the configured threshold has been exceeded for this output stream.
| |
| thresholdReached | back 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.
| |
| write | back to summary |
|---|---|
| public void write(final int b) throws IOException Implements abstract java. Writes the specified byte to this output stream.
| |
| write | back to summary |
|---|---|
| public void write(final byte[] b) throws IOException Overrides java. Writes
| |
| write | back to summary |
|---|---|
| public void write(final byte[] b, final int off, final int len) throws IOException Overrides java. Writes
| |