Class ZstdCompressCtx

  • All Implemented Interfaces:
    java.io.Closeable

    public class ZstdCompressCtx
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ZstdCompressCtx()
      Create a context for faster compress operations One such context is required for each thread - put this in a ThreadLocal.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      byte[] compress​(byte[] src)  
      int compress​(byte[] dst, byte[] src)  
      java.nio.ByteBuffer compress​(java.nio.ByteBuffer srcBuf)
      Compresses the data in buffer 'srcBuf'
      int compress​(java.nio.ByteBuffer dstBuf, java.nio.ByteBuffer srcBuf)
      Compresses the data in buffer 'srcBuf'
      int compressByteArray​(byte[] dstBuff, int dstOffset, int dstSize, byte[] srcBuff, int srcOffset, int srcSize)
      Compresses byte array 'srcBuff' into byte array 'dstBuff' reusing this ZstdCompressCtx.
      int compressDirectByteBuffer​(java.nio.ByteBuffer dstBuff, int dstOffset, int dstSize, java.nio.ByteBuffer srcBuff, int srcOffset, int srcSize)
      Compresses buffer 'srcBuff' into buffer 'dstBuff' reusing this ZstdCompressCtx.
      ZstdCompressCtx loadDict​(byte[] dict)
      Load compression dictionary to be used for subsequently compressed frames.
      ZstdCompressCtx loadDict​(ZstdDictCompress dict)
      Load compression dictionary to be used for subsequently compressed frames.
      ZstdCompressCtx setChecksum​(boolean checksumFlag)
      Enable or disable compression checksums
      ZstdCompressCtx setContentSize​(boolean contentSizeFlag)
      Enable or disable content size
      ZstdCompressCtx setDictID​(boolean dictIDFlag)
      Enable or disable dictID
      ZstdCompressCtx setLevel​(int level)
      Set compression level
      ZstdCompressCtx setLong​(int windowLog)
      Enable or disable LongDistanceMatching and set the window size
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ZstdCompressCtx

        public ZstdCompressCtx()
        Create a context for faster compress operations One such context is required for each thread - put this in a ThreadLocal.
    • Method Detail

      • setLevel

        public ZstdCompressCtx setLevel​(int level)
        Set compression level
        Parameters:
        level - compression level, default: 3
      • setChecksum

        public ZstdCompressCtx setChecksum​(boolean checksumFlag)
        Enable or disable compression checksums
        Parameters:
        checksumFlag - A 32-bits checksum of content is written at end of frame, default: false
      • setContentSize

        public ZstdCompressCtx setContentSize​(boolean contentSizeFlag)
        Enable or disable content size
        Parameters:
        contentSizeFlag - Content size will be written into frame header _whenever known_, default: true
      • setDictID

        public ZstdCompressCtx setDictID​(boolean dictIDFlag)
        Enable or disable dictID
        Parameters:
        dictIDFlag - When applicable, dictionary's ID is written into frame header, default: true
      • setLong

        public ZstdCompressCtx setLong​(int windowLog)
        Enable or disable LongDistanceMatching and set the window size
        Parameters:
        windowLog - Maximum allowed back-reference distance, expressed as power of 2. This will set a memory budget for streaming decompression, with larger values requiring more memory and typically compressing more. Must be clamped between 10 and 32/64 but values greater then 27 may not be decompressable in all context as they require more memory. 0 disables LDM.
      • loadDict

        public ZstdCompressCtx loadDict​(ZstdDictCompress dict)
        Load compression dictionary to be used for subsequently compressed frames.
        Parameters:
        dict - the dictionary or `null` to remove loaded dictionary
      • loadDict

        public ZstdCompressCtx loadDict​(byte[] dict)
        Load compression dictionary to be used for subsequently compressed frames.
        Parameters:
        dict - the dictionary or `null` to remove loaded dictionary
      • compressDirectByteBuffer

        public int compressDirectByteBuffer​(java.nio.ByteBuffer dstBuff,
                                            int dstOffset,
                                            int dstSize,
                                            java.nio.ByteBuffer srcBuff,
                                            int srcOffset,
                                            int srcSize)
        Compresses buffer 'srcBuff' into buffer 'dstBuff' reusing this ZstdCompressCtx. Destination buffer should be sized to handle worst cases situations (input data not compressible). Worst case size evaluation is provided by function ZSTD_compressBound(). This is a low-level function that does not take into account or affect the `limit` or `position` of source or destination buffers.
        Parameters:
        dstBuff - the destination buffer - must be direct
        dstOffset - the start offset of 'dstBuff'
        dstSize - the size of 'dstBuff' (after 'dstOffset')
        srcBuff - the source buffer - must be direct
        srcOffset - the start offset of 'srcBuff'
        srcSize - the length of 'srcBuff' (after 'srcOffset')
        Returns:
        the number of bytes written into buffer 'dstBuff'.
      • compressByteArray

        public int compressByteArray​(byte[] dstBuff,
                                     int dstOffset,
                                     int dstSize,
                                     byte[] srcBuff,
                                     int srcOffset,
                                     int srcSize)
        Compresses byte array 'srcBuff' into byte array 'dstBuff' reusing this ZstdCompressCtx. Destination buffer should be sized to handle worst cases situations (input data not compressible). Worst case size evaluation is provided by function ZSTD_compressBound().
        Parameters:
        dstBuff - the destination buffer (byte array)
        dstOffset - the start offset of 'dstBuff'
        dstSize - the size of 'dstBuff' (after 'dstOffset')
        srcBuff - the source buffer (byte array)
        srcOffset - the start offset of 'srcBuff'
        srcSize - the length of 'srcBuff' (after 'srcOffset')
        Returns:
        the number of bytes written into buffer 'dstBuff'.
      • compress

        public int compress​(java.nio.ByteBuffer dstBuf,
                            java.nio.ByteBuffer srcBuf)
        Compresses the data in buffer 'srcBuf'
        Parameters:
        dstBuf - the destination buffer - must be direct. It is assumed that the `position()` of this buffer marks the offset at which the compressed data are to be written, and that the `limit()` of this buffer is the maximum compressed data size to allow.

        When this method returns successfully, its `position()` will be set to its current `position()` plus the compressed size of the data.

        srcBuf - the source buffer - must be direct. It is assumed that the `position()` of this buffer marks the beginning of the uncompressed data to be compressed, and that the `limit()` of this buffer marks its end.

        When this method returns successfully, its `position()` will be set to the initial `limit()`.

        Returns:
        the size of the compressed data
      • compress

        public java.nio.ByteBuffer compress​(java.nio.ByteBuffer srcBuf)
                                     throws ZstdException
        Compresses the data in buffer 'srcBuf'
        Parameters:
        srcBuf - the source buffer - must be direct. It is assumed that the `position()` of the buffer marks the beginning of the uncompressed data to be compressed, and that the `limit()` of this buffer marks its end.

        When this method returns successfully, its `position()` will be set to its initial `limit()`.

        Returns:
        A newly allocated direct ByteBuffer containing the compressed data.
        Throws:
        ZstdException
      • compress

        public int compress​(byte[] dst,
                            byte[] src)
      • compress

        public byte[] compress​(byte[] src)
      • close

        public void close()
        Specified by:
        close in interface java.io.Closeable