Class StreamBuffer

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class StreamBuffer
    extends java.io.OutputStream
    Uses an in memory buffer to hold output until bufferSize data is written then will switch over to writing everything to a temp file. You get the data back by calling getInputStream() which can be called multiple times, each time returning a new InputStream with all the data. Calling getInputStream() will close the OutputStream and prevent additional writing.
    • Constructor Detail

      • StreamBuffer

        public StreamBuffer()
      • StreamBuffer

        public StreamBuffer​(java.io.InputStream in)
    • Method Detail

      • write

        public void write​(byte[] b)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(int b)
                   throws java.io.IOException
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        Throws:
        java.io.IOException
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        Returns the data that was written to this stream. If the stream is backed by a temp file, the file will be deleted when the inputStream is closed or finalized.
        Returns:
        a stream containing the data written to this stream
        Throws:
        java.io.IOException
      • finalize

        public void finalize()
                      throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • getContentType

        public java.lang.String getContentType()
      • withContentType

        public StreamBuffer withContentType​(java.lang.String contentType)
      • getLength

        public int getLength()
      • getBufferSize

        public long getBufferSize()
      • withBufferSize

        public StreamBuffer withBufferSize​(long bufferSize)
      • getTempFile

        public java.io.File getTempFile()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object