Class LZFOutputStream

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

    public class LZFOutputStream
    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.
    See Also:
    LZFInputStream, LZFCompressingInputStream
    • 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
      • _cfgFinishBlockOnFlush

        protected boolean _cfgFinishBlockOnFlush
        Configuration setting that governs whether basic 'flush()' should first complete a block or not.

        Default value is 'true'

      • _outputStreamClosed

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

      • LZFOutputStream

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

        public LZFOutputStream​(ChunkEncoder encoder,
                               java.io.OutputStream outputStream)
      • LZFOutputStream

        public LZFOutputStream​(java.io.OutputStream outputStream,
                               BufferRecycler bufferRecycler)
      • LZFOutputStream

        public LZFOutputStream​(ChunkEncoder encoder,
                               java.io.OutputStream outputStream,
                               BufferRecycler bufferRecycler)
      • LZFOutputStream

        public LZFOutputStream​(ChunkEncoder encoder,
                               java.io.OutputStream outputStream,
                               int bufferSize,
                               BufferRecycler bufferRecycler)
    • Method Detail

      • setFinishBlockOnFlush

        public LZFOutputStream setFinishBlockOnFlush​(boolean b)
        Method for defining whether call to flush() will also complete current block (similar to calling finishBlock()) or not.
      • write

        public void write​(int singleByte)
                   throws java.io.IOException
        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
        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).
      • getFinishBlockOnFlush

        public boolean getFinishBlockOnFlush()
        Accessor for checking whether call to "flush()" will first finish the current block or not.
      • finishBlock

        public LZFOutputStream finishBlock()
                                    throws java.io.IOException
        Method that can be used to force completion of the current block, which means that all buffered data will be compressed into an LZF block. This typically results in lower compression ratio as larger blocks compress better; but may be necessary for network connections to ensure timely sending of data.
        Throws:
        java.io.IOException
      • writeCompressedBlock

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

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