com.atlassian.core.spool
Class DeferredSpoolFileOutputStream
java.lang.Object
java.io.OutputStream
org.apache.commons.io.output.ThresholdingOutputStream
com.atlassian.core.spool.DeferredFileOutputStream
com.atlassian.core.spool.DeferredSpoolFileOutputStream
- All Implemented Interfaces:
- java.io.Closeable, java.io.Flushable
public class DeferredSpoolFileOutputStream
- extends DeferredFileOutputStream
This specialisation of DeferredFileOutputStream may be configured with a FileFactory so that files are only created
once the deferred threshold is reached. getInputStream() returns a SpoolFileInputStream to read the result,
which means that the deferred file will be deleted once the input stream is closed.
|
Method Summary |
java.io.InputStream |
getInputStream()
Return an input stream of the written data. |
boolean |
isClosed()
|
boolean |
isUnspooling()
|
protected void |
thresholdReached()
Switches the underlying output stream from a memory based stream to one that is backed by disk. |
| Methods inherited from class org.apache.commons.io.output.ThresholdingOutputStream |
checkThreshold, flush, getByteCount, getThreshold, isThresholdExceeded, write, write, write |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DeferredSpoolFileOutputStream
public DeferredSpoolFileOutputStream(int threshold,
java.io.File outputFile)
- Create a new DeferredSpoolFileOutputStream with the specified threshold and deferred file
- See Also:
#DeferredFileOutputStream(int, File)
DeferredSpoolFileOutputStream
public DeferredSpoolFileOutputStream(int threshold,
FileFactory fileFactory)
- Create a new DeferredSpoolFileOutputStream with the specified threshold and file factory. The file factory
will only be used when the threshold is reached, so you can defer the creation of files until they are necessary
- Parameters:
threshold - fileFactory - Factory to use when the deferred file must be created
isClosed
public boolean isClosed()
- Returns:
- True if the stream has been closed
isUnspooling
public boolean isUnspooling()
- Returns:
- True if getInputStream() has been called already
thresholdReached
protected void thresholdReached()
throws java.io.IOException
- Description copied from class:
DeferredFileOutputStream
- Switches the underlying output stream from a memory based stream to one that is backed by disk. This is the point
at which we realise that too much data is being written to keep in memory, so we elect to switch to disk-based
storage.
- Overrides:
thresholdReached in class DeferredFileOutputStream
- Throws:
java.io.IOException - if an error occurs.
getInputStream
public java.io.InputStream getInputStream()
throws java.io.IOException
- Return an input stream of the written data. This method may only be called once and only once the output stream
has been closed.
- Overrides:
getInputStream in class DeferredFileOutputStream
- Returns:
- A InputStream - If the deferred stream has been written to disk, a SpoolFileInputStream will be returned
and the deferred file will be deleted when this stream is closed.
- Throws:
java.io.IOException - If the output stream is not closed or an input stream has already been returned
Copyright © 2009 Atlassian Pty Ltd. All Rights Reserved.