Class PLZFOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, java.nio.channels.Channel, java.nio.channels.WritableByteChannel

    public class PLZFOutputStream
    extends java.io.FilterOutputStream
    implements java.nio.channels.WritableByteChannel
    Decorator OutputStream implementation that will compress output using LZF compression algorithm, given uncompressed input to write. Its counterpart is LZFInputStream; although in some ways LZFCompressingInputStream can be seen as the opposite.

    This class uses a parallel implementation to make use of all available cores, modulo system load.

    See Also:
    LZFInputStream, LZFCompressingInputStream, LZFOutputStream
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        PLZFOutputStream​(java.io.OutputStream outputStream)  
      protected PLZFOutputStream​(java.io.OutputStream outputStream, int nThreads)  
      protected PLZFOutputStream​(java.io.OutputStream outputStream, int bufferSize, int nThreads)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void checkNotClosed()  
      protected void checkWriteException()  
      void close()  
      void flush()
      This flush method does nothing.
      protected static int getNThreads()  
      java.io.OutputStream getUnderlyingOutputStream()
      Method that can be used to find underlying OutputStream that we write encoded LZF encoded data into, after compressing it.
      boolean isOpen()  
      void write​(byte[] buffer, int offset, int length)  
      void write​(int singleByte)
      WARNING: using this method will lead to very poor performance!
      void write​(java.io.InputStream in)  
      int write​(java.nio.ByteBuffer src)  
      void write​(java.nio.channels.FileChannel in)  
      protected void writeCompressedBlock()
      Compress and write the current block to the OutputStream
      • Methods inherited from class java.io.FilterOutputStream

        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
    • Field Detail

      • DEFAULT_OUTPUT_BUFFER_SIZE

        private static final int DEFAULT_OUTPUT_BUFFER_SIZE
        See Also:
        Constant Field Values
      • _outputBuffer

        protected byte[] _outputBuffer
      • _position

        protected int _position
      • _outputStreamClosed

        protected boolean _outputStreamClosed
        Flag that indicates if we have already called '_outputStream.close()' (to avoid calling it multiple times)
      • compressExecutor

        private final java.util.concurrent.ExecutorService compressExecutor
      • writeExecutor

        private final java.util.concurrent.ExecutorService writeExecutor
      • writeException

        volatile java.lang.Exception writeException
    • Constructor Detail

      • PLZFOutputStream

        public PLZFOutputStream​(java.io.OutputStream outputStream)
      • PLZFOutputStream

        protected PLZFOutputStream​(java.io.OutputStream outputStream,
                                   int nThreads)
      • PLZFOutputStream

        protected PLZFOutputStream​(java.io.OutputStream outputStream,
                                   int bufferSize,
                                   int nThreads)
    • Method Detail

      • getNThreads

        protected static int getNThreads()
      • write

        public void write​(int singleByte)
                   throws java.io.IOException
        WARNING: using this method will lead to very poor performance!
        Overrides:
        write in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] buffer,
                          int offset,
                          int length)
                   throws java.io.IOException
        Overrides:
        write in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(java.io.InputStream in)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public void write​(java.nio.channels.FileChannel in)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public int write​(java.nio.ByteBuffer src)
                  throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.WritableByteChannel
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        This flush method does nothing.
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • getUnderlyingOutputStream

        public java.io.OutputStream getUnderlyingOutputStream()
        Method that can be used to find underlying OutputStream that we write encoded LZF encoded data into, after compressing it. Will never return null; although underlying stream may be closed (if this stream has been closed).
      • writeCompressedBlock

        protected void writeCompressedBlock()
                                     throws java.io.IOException
        Compress and write the current block to the OutputStream
        Throws:
        java.io.IOException
      • checkWriteException

        protected void checkWriteException()
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • checkNotClosed

        protected void checkNotClosed()
                               throws java.io.IOException
        Throws:
        java.io.IOException