Class MemoryOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.commons.io.output.ThresholdingOutputStream
-
- com.aspectran.web.support.multipart.inmemory.MemoryOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class MemoryOutputStream extends org.apache.commons.io.output.ThresholdingOutputStream
An output stream which will retain data in memory (always).
-
-
Constructor Summary
Constructors Constructor Description MemoryOutputStream(long threshold)
Constructs an instance of this class which will trigger throw UnsupportedOperationException if the specified threshold is reached.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes underlying output stream, and mark this as closedbyte[]
getData()
Returns the data for this output stream as an array of bytes.protected java.io.OutputStream
getStream()
Returns the current output stream.boolean
isInMemory()
Determines whether or not the data for this output stream has been retained in memory.protected void
thresholdReached()
Not possible in GAE.void
writeTo(java.io.OutputStream out)
Writes the data from this output stream to the specified output stream, after it has been closed.
-
-
-
Method Detail
-
getStream
protected java.io.OutputStream getStream() throws java.io.IOException
Returns the current output stream. This may be memory based or disk based, depending on the current state with respect to the threshold.- Specified by:
getStream
in classorg.apache.commons.io.output.ThresholdingOutputStream
- Returns:
- the underlying output stream
- Throws:
java.io.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.- Specified by:
thresholdReached
in classorg.apache.commons.io.output.ThresholdingOutputStream
-
isInMemory
public boolean isInMemory()
Determines whether or not 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
public void close() throws java.io.IOException
Closes underlying output stream, and mark this as closed- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classorg.apache.commons.io.output.ThresholdingOutputStream
- Throws:
java.io.IOException
- if an error occurs
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOException
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:
java.io.IOException
- if this stream is not yet closed or an error occurs
-
-