org.subethamail.smtp.server.io
Class DeferredFileOutputStream
java.lang.Object
java.io.OutputStream
org.subethamail.smtp.server.io.ThresholdingOutputStream
org.subethamail.smtp.server.io.DeferredFileOutputStream
- All Implemented Interfaces:
- java.io.Closeable, java.io.Flushable
public class DeferredFileOutputStream
- extends ThresholdingOutputStream
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
Method Summary |
void |
close()
|
java.io.InputStream |
getInputStream()
Closes the output stream and creates an InputStream on the same data. |
protected void |
thresholdReached(int current,
int predicted)
Called when the threshold is about to be exceeded. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TMPFILE_PREFIX
public static final java.lang.String TMPFILE_PREFIX
- See Also:
- Constant Field Values
TMPFILE_SUFFIX
public static final java.lang.String TMPFILE_SUFFIX
- See Also:
- Constant Field Values
DeferredFileOutputStream
public DeferredFileOutputStream(int transitionSize)
- Parameters:
transitionSize
- is the number of bytes at which to convert
from a byte array to a real file.
thresholdReached
protected void thresholdReached(int current,
int predicted)
throws java.io.IOException
- Description copied from class:
ThresholdingOutputStream
- 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.
- Specified by:
thresholdReached
in class ThresholdingOutputStream
- Parameters:
current
- is the current number of bytes that have been writtenpredicted
- is the total number after the write completes
- Throws:
java.io.IOException
getInputStream
public java.io.InputStream getInputStream()
throws java.io.IOException
- 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:
java.io.IOException
close
public void close()
throws java.io.IOException
- Specified by:
close
in interface java.io.Closeable
- Overrides:
close
in class ThresholdingOutputStream
- Throws:
java.io.IOException