Class InMemoryOutputStream
java.lang.Object
java.io.OutputStream
org.apache.commons.io.output.ThresholdingOutputStream
com.aspectran.web.support.multipart.inmemory.InMemoryOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public class InMemoryOutputStream
extends org.apache.commons.io.output.ThresholdingOutputStream
An output stream which will retain data in memory (always).
-
Constructor Summary
ConstructorsConstructorDescriptionInMemoryOutputStream
(long threshold) Constructs an instance of this class which will trigger throw UnsupportedOperationException if the specified threshold is reached. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes underlying output stream, and mark this as closedbyte[]
getData()
Returns the data for this output stream as an array of bytes.protected OutputStream
Returns the current output stream.boolean
Determines whether the data for this output stream has been retained in memory.protected void
Not possible in GAE.void
writeTo
(OutputStream out) Writes the data from this output stream to the specified output stream, after it has been closed.Methods inherited from class org.apache.commons.io.output.ThresholdingOutputStream
checkThreshold, flush, getByteCount, getStream, getThreshold, isThresholdExceeded, resetByteCount, setByteCount, write, write, write
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
InMemoryOutputStream
public InMemoryOutputStream(long threshold) Constructs an instance of this class which will trigger throw UnsupportedOperationException if the specified threshold is reached.- Parameters:
threshold
- the number of bytes at which to trigger an event
-
-
Method Details
-
getOutputStream
Returns the current output stream. This may be memory based or disk based, depending on the current state with respect to the threshold.- Overrides:
getOutputStream
in classorg.apache.commons.io.output.ThresholdingOutputStream
- Returns:
- the underlying output stream
- Throws:
IOException
- if an error occurs
-
thresholdReached
protected void thresholdReached()Not possible in GAE. Will never reach!! If it happens, try changing max upload size setting.- Overrides:
thresholdReached
in classorg.apache.commons.io.output.ThresholdingOutputStream
-
isInMemory
public boolean isInMemory()Determines whether the data for this output stream has been retained in memory.- Returns:
- always
true
-
getData
public byte[] getData()Returns the data for this output stream as an array of bytes.- Returns:
- the data for this output stream, or
null
if no such data is available
-
close
Closes underlying output stream, and mark this as closed- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classorg.apache.commons.io.output.ThresholdingOutputStream
- Throws:
IOException
- if an error occurs
-
writeTo
Writes the data from this output stream to the specified output stream, after it has been closed.- Parameters:
out
- output stream to write to- Throws:
IOException
- if this stream is not yet closed or an error occurs
-