Class InMemoryOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes underlying output stream, and mark this as closed
      byte[] 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.
      • Methods inherited from class org.apache.commons.io.output.ThresholdingOutputStream

        checkThreshold, flush, getByteCount, getThreshold, isThresholdExceeded, resetByteCount, 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 Detail

      • 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 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 class org.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 class org.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 interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class org.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