Class ZstdOutputStream

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
com.github.luben.zstd.ZstdOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ZstdOutputStream extends FilterOutputStream
OutputStream filter that compresses the data using Zstd compression
  • Constructor Details

    • ZstdOutputStream

      @Deprecated public ZstdOutputStream(OutputStream outStream, int level, boolean closeFrameOnFlush, boolean useChecksums) throws IOException
      Deprecated.
      Use ZstdOutputStream() or ZstdOutputStream(level) and set the other params with the setters
      Throws:
      IOException
    • ZstdOutputStream

      @Deprecated public ZstdOutputStream(OutputStream outStream, int level, boolean closeFrameOnFlush) throws IOException
      Deprecated.
      Use ZstdOutputStream() or ZstdOutputStream(level) and set the other params with the setters
      Throws:
      IOException
    • ZstdOutputStream

      public ZstdOutputStream(OutputStream outStream, int level) throws IOException
      create a new compressing OutputStream
      Parameters:
      outStream - the stream to wrap
      level - the compression level
      Throws:
      IOException
    • ZstdOutputStream

      public ZstdOutputStream(OutputStream outStream) throws IOException
      create a new compressing OutputStream
      Parameters:
      outStream - the stream to wrap
      Throws:
      IOException
    • ZstdOutputStream

      public ZstdOutputStream(OutputStream outStream, BufferPool bufferPool, int level) throws IOException
      create a new compressing OutputStream
      Parameters:
      outStream - the stream to wrap
      bufferPool - the pool to fetch and return buffers
      Throws:
      IOException
    • ZstdOutputStream

      public ZstdOutputStream(OutputStream outStream, BufferPool bufferPool) throws IOException
      create a new compressing OutputStream
      Parameters:
      outStream - the stream to wrap
      bufferPool - the pool to fetch and return buffers
      Throws:
      IOException
  • Method Details

    • setFinalize

      @Deprecated public void setFinalize(boolean finalize)
      Deprecated.
      If you don't rely on finalizers, use `ZstdOutputStreamNoFinalizer` instead.
      Enable or disable class finalizers If finalizers are disabled the responsibility fir calling the `close` method is on the consumer.
      Parameters:
      finalize - default `true` - finalizers are enabled
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • recommendedCOutSize

      public static long recommendedCOutSize()
    • setChecksum

      public ZstdOutputStream setChecksum(boolean useChecksums) throws IOException
      Enable checksums for the compressed stream. Default: false
      Throws:
      IOException
    • setLevel

      public ZstdOutputStream setLevel(int level) throws IOException
      Set the compression level. Default: Zstd.defaultCompressionLevel()
      Throws:
      IOException
    • setLong

      public ZstdOutputStream setLong(int windowLog) throws IOException
      Set the Long Distance Matching. Values for windowLog outside the range 10-27 will disable and reset LDM
      Throws:
      IOException
    • setWorkers

      public ZstdOutputStream setWorkers(int n) throws IOException
      Enable use of worker threads for parallel compression. Default: no worker threads.
      Throws:
      IOException
    • setOverlapLog

      public ZstdOutputStream setOverlapLog(int overlapLog) throws IOException
      Advanced Compression Option: Set the amount of data reloaded from the previous job. See https://facebook.github.io/zstd/zstd_manual.html#Chapter5 for more information.
      Throws:
      IOException
    • setJobSize

      public ZstdOutputStream setJobSize(int jobSize) throws IOException
      Advanced Compression Option: Set the size of each compression job. Only applies when multi threaded compression is enabled. See https://facebook.github.io/zstd/zstd_manual.html#Chapter5 for more information.
      Throws:
      IOException
    • setTargetLength

      public ZstdOutputStream setTargetLength(int targetLength) throws IOException
      Advanced Compression Option: Set the target match length. See https://facebook.github.io/zstd/zstd_manual.html#Chapter5 for more information.
      Throws:
      IOException
    • setMinMatch

      public ZstdOutputStream setMinMatch(int minMatch) throws IOException
      Advanced Compression Option: Set the minimum match length. See https://facebook.github.io/zstd/zstd_manual.html#Chapter5 for more information.
      Throws:
      IOException
    • setSearchLog

      public ZstdOutputStream setSearchLog(int searchLog) throws IOException
      Advanced Compression Option: Set the maximum number of searches in a hash chain or a binary tree using logarithmic scale. See https://facebook.github.io/zstd/zstd_manual.html#Chapter5 for more information.
      Throws:
      IOException
    • setChainLog

      public ZstdOutputStream setChainLog(int chainLog) throws IOException
      Advanced Compression Option: Set the maximum number of bits for the secondary search structure. See https://facebook.github.io/zstd/zstd_manual.html#Chapter5 for more information.
      Throws:
      IOException
    • setHashLog

      public ZstdOutputStream setHashLog(int hashLog) throws IOException
      Advanced Compression Option: Set the maximum number of bits for a hash table. See https://facebook.github.io/zstd/zstd_manual.html#Chapter5 for more information.
      Throws:
      IOException
    • setWindowLog

      public ZstdOutputStream setWindowLog(int windowLog) throws IOException
      Advanced Compression Option: Set the maximum number of bits for a match distance. See https://facebook.github.io/zstd/zstd_manual.html#Chapter5 for more information.
      Throws:
      IOException
    • setStrategy

      public ZstdOutputStream setStrategy(int strategy) throws IOException
      Advanced Compression Option: Set the strategy used by a match finder. See https://facebook.github.io/zstd/zstd_manual.html#Chapter5 for more information.
      Throws:
      IOException
    • setCloseFrameOnFlush

      public ZstdOutputStream setCloseFrameOnFlush(boolean closeOnFlush)
      Enable closing the frame on flush. This will guarantee that it can be ready fully if the process crashes before closing the stream. On the downside it will negatively affect the compression ratio. Default: false.
    • setDict

      public ZstdOutputStream setDict(byte[] dict) throws IOException
      Throws:
      IOException
    • setDict

      public ZstdOutputStream setDict(ZstdDictCompress dict) throws IOException
      Throws:
      IOException
    • write

      public void write(byte[] src, int offset, int len) throws IOException
      Overrides:
      write in class FilterOutputStream
      Throws:
      IOException
    • write

      public void write(int i) throws IOException
      Overrides:
      write in class FilterOutputStream
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Flushes the output
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class FilterOutputStream
      Throws:
      IOException
    • close

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