ccs.utils
Class RepeatingSwappingBuffer

java.lang.Object
  extended by java.io.OutputStream
      extended by ccs.utils.SwappingBuffer
          extended by ccs.utils.RepeatingSwappingBuffer
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class RepeatingSwappingBuffer
extends SwappingBuffer

A SwappingBuffer which, once filled, can be written multiple times. The drawback is that you must call cleanup after all writes have completed. A try..finally construct is recommended. Failure to do this may result in a security breach. MT-UNSAFE.


Nested Class Summary
 
Nested classes/interfaces inherited from class ccs.utils.SwappingBuffer
SwappingBuffer.DestructiveBAIS, SwappingBuffer.PeekableBAOS
 
Field Summary
 
Fields inherited from class ccs.utils.SwappingBuffer
baos, cipher, cos, DEAD, DEFAULTSWAP, f, isFile, mimeType, phase, READCOMMITTED, UNWRITABLE, wad, WRITABLE
 
Constructor Summary
RepeatingSwappingBuffer()
          Creates a new RepeatingSwappingBuffer with a default threshold (512K) and default auto-destruct.
RepeatingSwappingBuffer(byte[] contents)
          Creates a new "pre-filled" SwappingBuffer whose contents are the supplied buffer.
RepeatingSwappingBuffer(int threshold)
          Creates a new SwappingBuffer with the supplied threshold and default auto-destruct.
RepeatingSwappingBuffer(int threshold, int autoDestruct)
          Creates a new SwappingBuffer with the supplied threshold and auto-destruct level.
 
Method Summary
 void cleanup()
          Cleans up after all writes have been completed.
 java.io.InputStream getInputStream()
          Returns a buffered input stream which reads from this buffer.
 void writeTo(java.io.OutputStream os)
          Writes the contents of the buffer to the supplied stream.
 
Methods inherited from class ccs.utils.SwappingBuffer
close, finalize, flush, getByteArray, getFile, getFilePath, getLifecycleStage, isWritable, randomRead, size, write, write
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RepeatingSwappingBuffer

public RepeatingSwappingBuffer()
Creates a new RepeatingSwappingBuffer with a default threshold (512K) and default auto-destruct.


RepeatingSwappingBuffer

public RepeatingSwappingBuffer(int threshold)
Creates a new SwappingBuffer with the supplied threshold and default auto-destruct.


RepeatingSwappingBuffer

public RepeatingSwappingBuffer(int threshold,
                               int autoDestruct)
Creates a new SwappingBuffer with the supplied threshold and auto-destruct level.

Parameters:
threshold - The threshold at which to swap to disk.
autoDestruct - The auto-destruct level for disk files; a constant from FileKiller.

RepeatingSwappingBuffer

public RepeatingSwappingBuffer(byte[] contents)
Creates a new "pre-filled" SwappingBuffer whose contents are the supplied buffer. This SwappingBuffer is effectively a ByteArrayInputStream in disguise.

Method Detail

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns a buffered input stream which reads from this buffer. Further writes are prohibited after this call. It is more efficient to use writeTo() if this will do the job.

Overrides:
getInputStream in class SwappingBuffer
Returns:
the input stream.
Throws:
java.io.IOException - if there is a problem during the process.

writeTo

public void writeTo(java.io.OutputStream os)
             throws java.io.IOException
Writes the contents of the buffer to the supplied stream. Further writes to the buffer are prohibited after this call.

Overrides:
writeTo in class SwappingBuffer
Parameters:
os - The stream to write to.
Throws:
java.io.IOException - if the call failed.

cleanup

public void cleanup()
Cleans up after all writes have been completed. Failure to do this may cause cruft to build up in Checkpoint's tmp folder, but is not a security risk. (Every temporary file is encrypted with an emphemeral key, and so cannot be decrypted once the SwappingBuffer that created it has been destroyed).