public abstract class ThresholdingOutputStream extends OutputStream
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.
Constructor and Description |
---|
ThresholdingOutputStream(int 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(int count)
Checks to see if writing the specified number of bytes would cause the
configured threshold to be exceeded.
|
void |
close()
Closes this output stream and releases any system resources associated
with this stream.
|
void |
flush()
Flushes this output stream and forces any buffered output bytes to be
written out.
|
protected abstract OutputStream |
getStream()
Returns the underlying output stream, to which the corresponding
OutputStream methods in this class will ultimately delegate. |
boolean |
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.
|
void |
write(byte[] b)
Writes
b.length bytes from the specified byte array to this
output stream. |
void |
write(byte[] b,
int off,
int len)
Writes
len bytes from the specified byte array starting at
offset off to this output stream. |
void |
write(int b)
Writes the specified byte to this output stream.
|
public ThresholdingOutputStream(int threshold)
threshold
- The number of bytes at which to trigger an event.public void write(int b) throws IOException
write
in class OutputStream
b
- The byte to be written.IOException
- if an error occurs.public void write(byte[] b) throws IOException
b.length
bytes from the specified byte array to this
output stream.write
in class OutputStream
b
- The array of bytes to be written.IOException
- if an error occurs.public void write(byte[] b, int off, int len) throws IOException
len
bytes from the specified byte array starting at
offset off
to this output stream.write
in class OutputStream
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.public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
- if an error occurs.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
- if an error occurs.public boolean isThresholdExceeded()
true
if the threshold has been reached;
false
otherwise.protected void checkThreshold(int count) throws IOException
count
- The number of bytes about to be written to the underlying
output stream.IOException
- if an error occurs.protected abstract OutputStream getStream() throws IOException
OutputStream
methods in this class will ultimately delegate.IOException
- if an error occurs.protected abstract void thresholdReached() throws IOException
IOException
- if an error occurs.Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.