com.atlassian.core.spool
Class DeferredSpoolFileOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.apache.commons.io.output.ThresholdingOutputStream
          extended by com.atlassian.core.spool.DeferredFileOutputStream
              extended by 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.


Field Summary
 
Fields inherited from class com.atlassian.core.spool.DeferredFileOutputStream
closed, outputFile
 
Constructor Summary
DeferredSpoolFileOutputStream(int threshold, java.io.File outputFile)
          Create a new DeferredSpoolFileOutputStream with the specified threshold and deferred file
DeferredSpoolFileOutputStream(int threshold, FileFactory fileFactory)
          Create a new DeferredSpoolFileOutputStream with the specified threshold and file factory.
 
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 com.atlassian.core.spool.DeferredFileOutputStream
close, getData, getFile, getStream, isInMemory, writeTo
 
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
 

Constructor Detail

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
Method Detail

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.