Class BlockLZ4CompressorOutputStream

java.lang.Object
java.io.OutputStream
org.apache.commons.compress.compressors.CompressorOutputStream
org.apache.commons.compress.compressors.lz4.BlockLZ4CompressorOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class BlockLZ4CompressorOutputStream extends CompressorOutputStream
CompressorOutputStream for the LZ4 block format.
Since:
1.14
See Also:
  • Field Details

  • Constructor Details

    • BlockLZ4CompressorOutputStream

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

      public BlockLZ4CompressorOutputStream(OutputStream os, Parameters params) throws 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:
      IOException - if reading fails
  • Method Details

    • write

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

      public void write(byte[] data, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException
    • finish

      public void finish() throws IOException
      Compresses all remaining data and writes it to the stream, doesn't close the underlying stream.
      Throws:
      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:
      IllegalStateException - if the stream has already started to write data
      See Also:
    • addLiteralBlock

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

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

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

      private void recordLiteral(byte[] b)
    • clearUnusedBlocksAndPairs

      private void clearUnusedBlocksAndPairs()
    • clearUnusedBlocks

      private void clearUnusedBlocks()
    • recordBackReference

      private void recordBackReference(LZ77Compressor.BackReference block)
    • 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 IOException
      Throws:
      IOException
    • writeWritablePairs

      private void writeWritablePairs(int lengthOfBlocksAfterLastPair) throws IOException
      Throws:
      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