Methods Summary |
---|
public byte[] | getData()Returns the data for this output stream as an array of bytes, assuming
that the data has been retained in memory. If the data was written to
disk, this method returns null .
if (memoryOutputStream != null)
{
return memoryOutputStream.toByteArray();
}
return null;
|
public java.io.File | getFile()Returns the data for this output stream as a File , assuming
that the data was written to disk. If the data was retained in memory,
this method returns null .
return outputFile;
|
protected java.io.OutputStream | getStream()Returns the current output stream. This may be memory based or disk
based, depending on the current state with respect to the threshold.
return currentOutputStream;
|
public boolean | isInMemory()Determines whether or not the data for this output stream has been
retained in memory.
return (!isThresholdExceeded());
|
protected void | thresholdReached()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.
byte[] data = memoryOutputStream.toByteArray();
FileOutputStream fos = new FileOutputStream(outputFile);
fos.write(data);
diskOutputStream = fos;
currentOutputStream = fos;
memoryOutputStream = null;
|