Class BlockLZ4CompressorOutputStream

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

    public class BlockLZ4CompressorOutputStream
    extends CompressorOutputStream
    CompressorOutputStream for the LZ4 block format.
    Since:
    1.14
    See Also:
    LZ4 Block Format Description
    • Field Detail

      • MIN_BACK_REFERENCE_LENGTH

        private static final int MIN_BACK_REFERENCE_LENGTH
        See Also:
        Constant Field Values
      • MIN_OFFSET_OF_LAST_BACK_REFERENCE

        private static final int MIN_OFFSET_OF_LAST_BACK_REFERENCE
        See Also:
        Constant Field Values
      • os

        private final java.io.OutputStream os
      • oneByte

        private final byte[] oneByte
      • finished

        private boolean finished
      • expandedBlocks

        private java.util.Deque<byte[]> expandedBlocks
    • Constructor Detail

      • BlockLZ4CompressorOutputStream

        public BlockLZ4CompressorOutputStream​(java.io.OutputStream os)
                                       throws java.io.IOException
        Creates a new LZ4 output stream.
        Parameters:
        os - An OutputStream to read compressed data from
        Throws:
        java.io.IOException - if reading fails
      • BlockLZ4CompressorOutputStream

        public BlockLZ4CompressorOutputStream​(java.io.OutputStream os,
                                              Parameters params)
                                       throws java.io.IOException
        Creates a new LZ4 output stream.
        Parameters:
        os - An OutputStream to read compressed data from
        params - The parameters to use for LZ77 compression.
        Throws:
        java.io.IOException - if reading fails
    • Method Detail

      • write

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

        public void write​(byte[] data,
                          int off,
                          int len)
                   throws java.io.IOException
        Overrides:
        write 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
      • finish

        public void finish()
                    throws java.io.IOException
        Compresses all remaining data and writes it to the stream, doesn't close the underlying stream.
        Throws:
        java.io.IOException - if an error occurs
      • prefill

        public void prefill​(byte[] data,
                            int off,
                            int len)
        Adds some initial data to fill the window with.
        Parameters:
        data - the data to fill the window with.
        off - offset of real data into the array
        len - amount of data
        Throws:
        java.lang.IllegalStateException - if the stream has already started to write data
        See Also:
        LZ77Compressor.prefill(byte[])
      • addLiteralBlock

        private void addLiteralBlock​(LZ77Compressor.LiteralBlock block)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • addBackReference

        private void addBackReference​(LZ77Compressor.BackReference block)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeBlocksAndReturnUnfinishedPair

        private BlockLZ4CompressorOutputStream.Pair writeBlocksAndReturnUnfinishedPair​(int length)
                                                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • recordLiteral

        private void recordLiteral​(byte[] b)
      • clearUnusedBlocksAndPairs

        private void clearUnusedBlocksAndPairs()
      • clearUnusedBlocks

        private void clearUnusedBlocks()
      • expand

        private byte[] expand​(int offset,
                              int length)
      • expandFromList

        private void expandFromList​(byte[] expanded,
                                    int offset,
                                    int length)
      • clearUnusedPairs

        private void clearUnusedPairs()
      • writeFinalLiteralBlock

        private void writeFinalLiteralBlock()
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeWritablePairs

        private void writeWritablePairs​(int lengthOfBlocksAfterLastPair)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • rewriteLastPairs

        private void rewriteLastPairs()
      • createParameterBuilder

        public static Parameters.Builder createParameterBuilder()
        Returns a builder correctly configured for the LZ4 algorithm.
        Returns:
        a builder correctly configured for the LZ4 algorithm