Package org.subethamail.smtp.io
Class DeferredFileOutputStream
java.lang.Object
java.io.OutputStream
org.subethamail.smtp.io.ThresholdingOutputStream
org.subethamail.smtp.io.DeferredFileOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
This works like a ByteArrayOutputStream until a certain size is
reached, then creates a temp file and acts like a buffered
FileOutputStream. The data can be retreived afterwards by
calling getInputStream().
When this object is closed, the temporary file is deleted. You
can no longer call getInputStream().
- Author:
- Jeff Schnitzer
-
Field Summary
FieldsFields inherited from class org.subethamail.smtp.io.ThresholdingOutputStream
output -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the output stream and creates an InputStream on the same data.protected voidthresholdReached(int current, int predicted) Called when the threshold is about to be exceeded.Methods inherited from class org.subethamail.smtp.io.ThresholdingOutputStream
checkThreshold, flush, getThreshold, write, write, writeMethods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
TMPFILE_PREFIX
- See Also:
-
TMPFILE_SUFFIX
- See Also:
-
-
Constructor Details
-
DeferredFileOutputStream
public DeferredFileOutputStream(int transitionSize) - Parameters:
transitionSize- is the number of bytes at which to convert from a byte array to a real file.
-
-
Method Details
-
thresholdReached
Description copied from class:ThresholdingOutputStreamCalled 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.- Specified by:
thresholdReachedin classThresholdingOutputStream- Parameters:
current- is the current number of bytes that have been writtenpredicted- is the total number after the write completes- Throws:
IOException
-
getInputStream
Closes the output stream and creates an InputStream on the same data.- Returns:
- either a BetterByteArrayOutputStream or buffered FileInputStream, depending on what state we are in.
- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classThresholdingOutputStream- Throws:
IOException
-