public class ThresholdingOutputStream
extends java.io.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.
|
ThresholdingOutputStream(int threshold,
IOConsumer<ThresholdingOutputStream> thresholdConsumer,
IOFunction<ThresholdingOutputStream,java.io.OutputStream> outputStreamGetter)
Constructs an instance of this class which will trigger an event at the specified threshold.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
long |
getByteCount()
Returns the number of bytes that have been written to this output stream.
|
int |
getThreshold()
Returns the threshold, in bytes, at which an event will be triggered.
|
boolean |
isThresholdExceeded()
Determines whether or not the configured threshold has been exceeded for this output stream.
|
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 ThresholdingOutputStream(int threshold,
IOConsumer<ThresholdingOutputStream> thresholdConsumer,
IOFunction<ThresholdingOutputStream,java.io.OutputStream> outputStreamGetter)
threshold - The number of bytes at which to trigger an event.thresholdConsumer - Accepts reaching the threshold.outputStreamGetter - Gets the output stream.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.OutputStreamjava.io.IOException - if an error occurs.public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOException - if an error occurs.public long getByteCount()
public int getThreshold()
public boolean isThresholdExceeded()
true if the threshold has been reached; false otherwise.public void write(byte[] b)
throws java.io.IOException
b.length bytes from the specified byte array to this output stream.write in class java.io.OutputStreamb - The array of bytes to be written.java.io.IOException - if an error occurs.public void write(byte[] b,
int off,
int len)
throws java.io.IOException
len bytes from the specified byte array starting at offset off to this output stream.write in class java.io.OutputStreamb - 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.java.io.IOException - if an error occurs.public void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamb - The byte to be written.java.io.IOException - if an error occurs.Copyright © 2010 - 2023 Adobe. All Rights Reserved