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

    Constructors
    Constructor
    Description
    InMemoryOutputStream(long threshold)
    Constructs an instance of this class which will trigger throw UnsupportedOperationException if the specified threshold is reached.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes underlying output stream, and mark this as closed
    byte[]
    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
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      protected OutputStream getOutputStream() throws IOException
      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 class org.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 class org.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

      public void close() throws IOException
      Closes underlying output stream, and mark this as closed
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class org.apache.commons.io.output.ThresholdingOutputStream
      Throws:
      IOException - if an error occurs
    • writeTo

      public void writeTo(OutputStream out) throws 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:
      IOException - if this stream is not yet closed or an error occurs