Package org.subethamail.smtp.io
Class ThresholdingOutputStream
java.lang.Object
java.io.OutputStream
org.subethamail.smtp.io.ThresholdingOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
- Direct Known Subclasses:
DeferredFileOutputStream
This is an OutputStream wrapper which takes notice when a
threshold (number of bytes) is about to be written. This can
be used to limit output data, swap writers, etc.
- Author:
- Jeff Schnitzer
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckThreshold(int count) Checks whether reading count bytes would cross the limit.voidclose()voidflush()intprotected abstract voidthresholdReached(int current, int predicted) Called when the threshold is about to be exceeded.voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
output
-
-
Constructor Details
-
ThresholdingOutputStream
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
checkThreshold
Checks whether reading count bytes would cross the limit.- Throws:
IOException
-
getThreshold
public int getThreshold()- Returns:
- the current threshold value.
-
thresholdReached
Called when the threshold is about to be exceeded. This isn't exact; it's called whenever a write would occur that would cross the amount. Once it is called, it isn't called again.- Parameters:
current- is the current number of bytes that have been writtenpredicted- is the total number after the write completes- Throws:
IOException
-