Class Zstd

java.lang.Object
com.github.luben.zstd.Zstd

public class Zstd extends Object
  • Constructor Details

    • Zstd

      public Zstd()
  • Method Details

    • compress

      public static long compress(byte[] dst, byte[] src, int level, boolean checksumFlag)
      Compresses buffer 'src' into buffer 'dst'. 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:
      dst - the destination buffer
      src - the source buffer
      level - compression level
      checksumFlag - flag to enable or disable checksum
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compress

      public static long compress(byte[] dst, byte[] src, int level)
      Compresses buffer 'src' into buffer 'dst'. 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:
      dst - the destination buffer
      src - the source buffer
      level - compression level
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compressByteArray

      public static long compressByteArray(byte[] dst, int dstOffset, int dstSize, byte[] src, int srcOffset, int srcSize, int level, boolean checksumFlag)
      Compresses buffer 'src' into buffer 'dst'. 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:
      dst - the destination buffer
      dstOffset - offset from the start of the destination buffer
      dstSize - available space in the destination buffer after the offset
      src - the source buffer
      srcOffset - offset from the start of the source buffer
      srcSize - available data in the source buffer after the offset
      level - compression level
      checksumFlag - flag to enable or disable checksum
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compressByteArray

      public static long compressByteArray(byte[] dst, int dstOffset, int dstSize, byte[] src, int srcOffset, int srcSize, int level)
      Compresses buffer 'src' into buffer 'dst'. 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:
      dst - the destination buffer
      dstOffset - offset from the start of the destination buffer
      dstSize - available space in the destination buffer after the offset
      src - the source buffer
      srcOffset - offset from the start of the source buffer
      srcSize - available data in the source buffer after the offset
      level - compression level
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compressDirectByteBuffer

      public static long compressDirectByteBuffer(ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcOffset, int srcSize, int level, boolean checksumFlag)
      Compresses direct buffer 'src' into direct buffer 'dst'. 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:
      dst - the destination buffer
      dstOffset - offset from the start of the destination buffer
      dstSize - available space in the destination buffer after the offset
      src - the source buffer
      srcOffset - offset from the start of the source buffer
      srcSize - available data in the source buffer after the offset
      level - compression level
      checksumFlag - flag to enable or disable checksum
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compressDirectByteBuffer

      public static long compressDirectByteBuffer(ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcOffset, int srcSize, int level)
      Compresses direct buffer 'src' into direct buffer 'dst'. 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:
      dst - the destination buffer
      dstOffset - offset from the start of the destination buffer
      dstSize - available space in the destination buffer after the offset
      src - the source buffer
      srcOffset - offset from the start of the source buffer
      srcSize - available data in the source buffer after the offset
      level - compression level
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compressUnsafe

      public static long compressUnsafe(long dst, long dstSize, long src, long srcSize, int level, boolean checksumFlag)
      Compresses buffer 'src' into direct buffer 'dst'. 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:
      dst - pointer to the destination buffer
      dstSize - available space in the destination buffer
      src - pointer to the source buffer
      srcSize - available data in the source buffer
      level - compression level
      checksumFlag - flag to enable or disable checksum
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compressUnsafe

      public static long compressUnsafe(long dst, long dstSize, long src, long srcSize, int level)
      Compresses buffer 'src' into direct buffer 'dst'. 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:
      dst - pointer to the destination buffer
      dstSize - available space in the destination buffer
      src - pointer to the source buffer
      srcSize - available data in the source buffer
      level - compression level
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compressUsingDict

      public static long compressUsingDict(byte[] dst, int dstOffset, byte[] src, int srcOffset, int length, byte[] dict, int level)
      Compresses buffer 'src' into buffer 'dst' with dictionary. 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:
      dst - the destination buffer
      dstOffset - the start offset of 'dst'
      src - the source buffer
      srcOffset - the start offset of 'src'
      length - the length of available data in 'src' after `srcOffset'
      dict - the dictionary buffer
      level - compression level
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compressUsingDict

      public static long compressUsingDict(byte[] dst, int dstOffset, byte[] src, int srcOffset, byte[] dict, int level)
      Compresses buffer 'src' into buffer 'dst' with dictionary. 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:
      dst - the destination buffer
      dstOffset - the start offset of 'dst'
      src - the source buffer
      srcOffset - the start offset of 'src'
      dict - the dictionary buffer
      level - compression level
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compressDirectByteBufferUsingDict

      public static long compressDirectByteBufferUsingDict(ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcOffset, int srcSize, byte[] dict, int level)
      Compresses direct byte buffer 'src' into direct byte buffer 'dst' with dictionary. 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:
      dst - the destination buffer
      dstOffset - the start offset of 'dst'
      dstSize - size of 'dst'
      src - the source buffer
      srcOffset - the start offset of 'src'
      srcSize - the length of 'src'
      dict - the dictionary buffer
      level - compression level
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compressFastDict

      public static long compressFastDict(byte[] dst, int dstOffset, byte[] src, int srcOffset, int length, ZstdDictCompress dict)
      Compresses buffer 'src' into buffer 'dst' with dictionary. 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:
      dst - the destination buffer
      dstOffset - the start offset of 'dst'
      src - the source buffer
      srcOffset - the start offset of 'src'
      length - the length of available data in 'src' after `srcOffset'
      dict - the dictionary
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compressFastDict

      public static long compressFastDict(byte[] dst, int dstOffset, byte[] src, int srcOffset, ZstdDictCompress dict)
      Compresses buffer 'src' into buffer 'dst' with dictionary. 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:
      dst - the destination buffer
      dstOffset - the start offset of 'dst'
      src - the source buffer
      srcOffset - the start offset of 'src'
      dict - the dictionary
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compress

      public static long compress(byte[] dst, byte[] src, ZstdDictCompress dict)
    • compressDirectByteBufferFastDict

      public static long compressDirectByteBufferFastDict(ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcOffset, int srcSize, ZstdDictCompress dict)
      Compresses buffer 'src' into buffer 'dst' with dictionary. 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:
      dst - the destination buffer
      dstOffset - the start offset of 'dst'
      dstSize - the size of 'dst'
      src - the source buffer
      srcOffset - the start offset of 'src'
      srcSize - the length of 'src'
      dict - the dictionary
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • decompress

      public static long decompress(byte[] dst, byte[] src)
      Decompresses buffer 'src' into buffer 'dst'. Destination buffer should be sized to be larger of equal to the originalSize
      Parameters:
      dst - the destination buffer
      src - the source buffer
      Returns:
      the number of bytes decompressed into destination buffer (originalSize) or an errorCode if it fails (which can be tested using ZSTD_isError())
    • decompressByteArray

      public static long decompressByteArray(byte[] dst, int dstOffset, int dstSize, byte[] src, int srcOffset, int srcSize)
      Decompresses buffer 'src' into buffer 'dst'. Destination buffer should be sized to be larger of equal to the originalSize
      Parameters:
      dst - the destination buffer
      dstOffset - offset from the start of the destination buffer
      dstSize - available space in the destination buffer after the offset
      src - the source buffer
      srcOffset - offset from the start of the source buffer
      srcSize - available data in the source buffer after the offset
      Returns:
      the number of bytes decompressed into destination buffer (originalSize) or an errorCode if it fails (which can be tested using ZSTD_isError())
    • decompressDirectByteBuffer

      public static long decompressDirectByteBuffer(ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcOffset, int srcSize)
      Decompresses direct buffer 'src' into direct buffer 'dst'. Destination buffer should be sized to be larger of equal to the originalSize
      Parameters:
      dst - the destination buffer
      dstOffset - offset from the start of the destination buffer
      dstSize - available space in the destination buffer after the offset
      src - the source buffer
      srcOffset - offset from the start of the source buffer
      srcSize - available data in the source buffer after the offset
      Returns:
      the number of bytes decompressed into destination buffer (originalSize) or an errorCode if it fails (which can be tested using ZSTD_isError())
    • decompressUnsafe

      public static long decompressUnsafe(long dst, long dstSize, long src, long srcSize)
      Decompresses buffer 'src' into direct buffer 'dst'. Destination buffer should be sized to be larger of equal to the originalSize
      Parameters:
      dst - pointer to the destination buffer
      dstSize - available space in the destination buffer after the offset
      src - pointer the source buffer
      srcSize - available data in the source buffer after the offset
      Returns:
      the number of bytes decompressed into destination buffer (originalSize) or an errorCode if it fails (which can be tested using ZSTD_isError())
    • decompressUsingDict

      public static long decompressUsingDict(byte[] dst, int dstOffset, byte[] src, int srcOffset, int length, byte[] dict)
      Decompresses buffer 'src' into buffer 'dst' with dictionary. Destination buffer should be sized to be larger of equal to the originalSize
      Parameters:
      dst - the destination buffer
      dstOffset - the start offset of 'dst'
      src - the source buffer
      srcOffset - the start offset of 'src'
      length - the length of 'src'
      dict - the dictionary buffer
      Returns:
      the number of bytes decompressed into destination buffer (originalSize) or an errorCode if it fails (which can be tested using ZSTD_isError())
    • decompressDirectByteBufferUsingDict

      public static long decompressDirectByteBufferUsingDict(ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcOffset, int srcSize, byte[] dict)
      Decompresses buffer 'src' into buffer 'dst' with dictionary. Destination buffer should be sized to be larger of equal to the originalSize
      Parameters:
      dst - the destination buffer
      dstOffset - the start offset of 'dst'
      dstSize - size of 'dst'
      src - the source buffer
      srcOffset - the start offset of 'src'
      srcSize - the size of 'src'
      dict - the dictionary buffer
      Returns:
      the number of bytes decompressed into destination buffer (originalSize) or an errorCode if it fails (which can be tested using ZSTD_isError())
    • decompressFastDict

      public static long decompressFastDict(byte[] dst, int dstOffset, byte[] src, int srcOffset, int length, ZstdDictDecompress dict)
      Decompresses buffer 'src' into buffer 'dst' with dictionary. Destination buffer should be sized to be larger of equal to the originalSize
      Parameters:
      dst - the destination buffer
      dstOffset - the start offset of 'dst'
      src - the source buffer
      srcOffset - the start offset of 'src'
      length - the length of 'src'
      dict - the dictionary
      Returns:
      the number of bytes decompressed into destination buffer (originalSize) or an errorCode if it fails (which can be tested using ZSTD_isError())
    • decompressDirectByteBufferFastDict

      public static long decompressDirectByteBufferFastDict(ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcOffset, int srcSize, ZstdDictDecompress dict)
      Decompresses buffer 'src' into buffer 'dst' with dictionary. Destination buffer should be sized to be larger of equal to the originalSize
      Parameters:
      dst - the destination buffer
      dstOffset - the start offset of 'dst'
      dstSize - the size of 'dst'
      src - the source buffer
      srcOffset - the start offset of 'src'
      srcSize - the size of 'src'
      dict - the dictionary
      Returns:
      the number of bytes decompressed into destination buffer (originalSize) or an errorCode if it fails (which can be tested using ZSTD_isError())
    • loadDictDecompress

      public static int loadDictDecompress(long stream, byte[] dict, int dict_size)
    • loadFastDictDecompress

      public static int loadFastDictDecompress(long stream, ZstdDictDecompress dict)
    • loadDictCompress

      public static int loadDictCompress(long stream, byte[] dict, int dict_size)
    • loadFastDictCompress

      public static int loadFastDictCompress(long stream, ZstdDictCompress dict)
    • setCompressionChecksums

      public static int setCompressionChecksums(long stream, boolean useChecksums)
    • setCompressionLevel

      public static int setCompressionLevel(long stream, int level)
    • setCompressionLong

      public static int setCompressionLong(long stream, int windowLog)
    • setCompressionWorkers

      public static int setCompressionWorkers(long stream, int workers)
    • decompressedSize

      public static long decompressedSize(byte[] src, int srcPosition, int srcSize)
      Return the original size of a compressed buffer (if known)
      Parameters:
      src - the compressed buffer
      srcPosition - offset of the compressed data inside the src buffer
      srcSize - length of the compressed data inside the src buffer
      Returns:
      the number of bytes of the original buffer 0 if the original size is not known
    • decompressedSize0

      private static long decompressedSize0(byte[] src, int srcPosition, int srcSize)
    • decompressedSize

      public static long decompressedSize(byte[] src, int srcPosition)
      Return the original size of a compressed buffer (if known)
      Parameters:
      src - the compressed buffer
      srcPosition - offset of the compressed data inside the src buffer
      Returns:
      the number of bytes of the original buffer 0 if the original size is not known
    • decompressedSize

      public static long decompressedSize(byte[] src)
      Return the original size of a compressed buffer (if known)
      Parameters:
      src - the compressed buffer
      Returns:
      the number of bytes of the original buffer 0 if the original size is not known
    • decompressedDirectByteBufferSize

      public static long decompressedDirectByteBufferSize(ByteBuffer src, int srcPosition, int srcSize)
      Return the original size of a compressed buffer (if known)
      Parameters:
      src - the compressed buffer
      srcPosition - offset of the compressed data inside the src buffer
      srcSize - length of the compressed data inside the src buffe
      Returns:
      the number of bytes of the original buffer 0 if the original size is not known
    • compressBound

      public static long compressBound(long srcSize)
      Maximum size of the compressed data
      Parameters:
      srcSize - the size of the data to be compressed
      Returns:
      the maximum size of the compressed data
    • isError

      public static boolean isError(long code)
      Error handling
      Parameters:
      code - return code/size
      Returns:
      if the return code signals an error
    • getErrorName

      public static String getErrorName(long code)
    • getErrorCode

      public static long getErrorCode(long code)
    • errNoError

      public static long errNoError()
    • errGeneric

      public static long errGeneric()
    • errPrefixUnknown

      public static long errPrefixUnknown()
    • errVersionUnsupported

      public static long errVersionUnsupported()
    • errFrameParameterUnsupported

      public static long errFrameParameterUnsupported()
    • errFrameParameterWindowTooLarge

      public static long errFrameParameterWindowTooLarge()
    • errCorruptionDetected

      public static long errCorruptionDetected()
    • errChecksumWrong

      public static long errChecksumWrong()
    • errDictionaryCorrupted

      public static long errDictionaryCorrupted()
    • errDictionaryWrong

      public static long errDictionaryWrong()
    • errDictionaryCreationFailed

      public static long errDictionaryCreationFailed()
    • errParameterUnsupported

      public static long errParameterUnsupported()
    • errParameterOutOfBound

      public static long errParameterOutOfBound()
    • errTableLogTooLarge

      public static long errTableLogTooLarge()
    • errMaxSymbolValueTooLarge

      public static long errMaxSymbolValueTooLarge()
    • errMaxSymbolValueTooSmall

      public static long errMaxSymbolValueTooSmall()
    • errStageWrong

      public static long errStageWrong()
    • errInitMissing

      public static long errInitMissing()
    • errMemoryAllocation

      public static long errMemoryAllocation()
    • errWorkSpaceTooSmall

      public static long errWorkSpaceTooSmall()
    • errDstSizeTooSmall

      public static long errDstSizeTooSmall()
    • errSrcSizeWrong

      public static long errSrcSizeWrong()
    • errDstBufferNull

      public static long errDstBufferNull()
    • trainFromBuffer

      public static long trainFromBuffer(byte[][] samples, byte[] dictBuffer, boolean legacy)
      Creates a new dictionary to tune a kind of samples
      Parameters:
      samples - the samples buffer array
      dictBuffer - the new dictionary buffer
      legacy - use the legacy training algorithm; otherwise cover
      Returns:
      the number of bytes into buffer 'dictBuffer' or an error code if it fails (which can be tested using ZSTD_isError())
    • trainFromBufferDirect

      public static long trainFromBufferDirect(ByteBuffer samples, int[] sampleSizes, ByteBuffer dictBuffer, boolean legacy)
      Creates a new dictionary to tune a kind of samples
      Parameters:
      samples - the samples direct byte buffer array
      sampleSizes - java integer array of sizes
      dictBuffer - the new dictionary buffer (preallocated direct byte buffer)
      legacy - use the legacy training algorithm; oter
      Returns:
      the number of bytes into buffer 'dictBuffer' or an error code if it fails (which can be tested using ZSTD_isError())
    • getDictIdFromFrame

      public static long getDictIdFromFrame(byte[] src)
      Get DictId from a compressed frame
      Parameters:
      src - compressed frame
      Returns:
      DictId or 0 if not available
    • getDictIdFromFrameBuffer

      public static long getDictIdFromFrameBuffer(ByteBuffer src)
      Get DictId from a compressed ByteBuffer frame
      Parameters:
      src - compressed frame
      Returns:
      DictId or 0 if not available
    • getDictIdFromDict

      public static long getDictIdFromDict(byte[] dict)
      Get DictId of a dictionary
      Parameters:
      dict - dictionary
      Returns:
      DictId or 0 if not available
    • trainFromBuffer

      public static long trainFromBuffer(byte[][] samples, byte[] dictBuffer)
      Creates a new dictionary to tune a kind of samples (uses Cover algorithm)
      Parameters:
      samples - the samples buffer array
      dictBuffer - the new dictionary buffer
      Returns:
      the number of bytes into buffer 'dictBuffer' or an error code if it fails (which can be tested using ZSTD_isError())
    • trainFromBufferDirect

      public static long trainFromBufferDirect(ByteBuffer samples, int[] sampleSizes, ByteBuffer dictBuffer)
      Creates a new dictionary to tune a kind of samples (uses Cover algorithm)
      Parameters:
      samples - the samples direct byte buffer array
      sampleSizes - java integer array of sizes
      dictBuffer - the new dictionary buffer (preallocated direct byte buffer)
      Returns:
      the number of bytes into buffer 'dictBuffer' or an error code if it fails (which can be tested using ZSTD_isError())
    • magicNumber

      public static int magicNumber()
    • windowLogMin

      public static int windowLogMin()
    • windowLogMax

      public static int windowLogMax()
    • chainLogMin

      public static int chainLogMin()
    • chainLogMax

      public static int chainLogMax()
    • hashLogMin

      public static int hashLogMin()
    • hashLogMax

      public static int hashLogMax()
    • searchLogMin

      public static int searchLogMin()
    • searchLogMax

      public static int searchLogMax()
    • searchLengthMin

      public static int searchLengthMin()
    • searchLengthMax

      public static int searchLengthMax()
    • blockSizeMax

      public static int blockSizeMax()
    • defaultCompressionLevel

      public static int defaultCompressionLevel()
    • minCompressionLevel

      public static int minCompressionLevel()
    • maxCompressionLevel

      public static int maxCompressionLevel()
    • compress

      public static byte[] compress(byte[] src) throws ZstdException
      Compresses the data in buffer 'src' using default compression level
      Parameters:
      src - the source buffer
      Returns:
      byte array with the compressed data
      Throws:
      ZstdException
    • compress

      public static byte[] compress(byte[] src, int level) throws ZstdException
      Compresses the data in buffer 'src'
      Parameters:
      src - the source buffer
      level - compression level
      Returns:
      byte array with the compressed data
      Throws:
      ZstdException
    • compress

      public static int compress(ByteBuffer dstBuf, ByteBuffer srcBuf) throws ZstdException
      Compresses the data in buffer 'srcBuf' using default compression level
      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, dstBuf's 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, srcBuf's position() will be set to its limit().

      Returns:
      the size of the compressed data
      Throws:
      ZstdException
    • compress

      public static int compress(ByteBuffer dstBuf, ByteBuffer srcBuf, int level, boolean checksumFlag) throws ZstdException
      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, dstBuf's 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, srcBuf's position() will be set to its limit().

      level - compression level
      Returns:
      the size of the compressed data
      Throws:
      ZstdException
    • compress

      public static int compress(ByteBuffer dstBuf, ByteBuffer srcBuf, int level) throws ZstdException
      Throws:
      ZstdException
    • compress

      public static ByteBuffer compress(ByteBuffer srcBuf, int level) throws ZstdException
      Compresses the data in buffer 'srcBuf'
      Parameters:
      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, srcBuf's position() will be set to its limit().

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

      public static byte[] compress(byte[] src, ZstdDictCompress dict) throws ZstdException
      Compresses the data in buffer 'src'
      Parameters:
      src - the source buffer
      dict - dictionary to use
      Returns:
      byte array with the compressed data
      Throws:
      ZstdException
    • compressUsingDict

      @Deprecated public static long compressUsingDict(byte[] dst, byte[] src, byte[] dict, int level)
      Deprecated.
      Use compress(dst, src, dict, level) instead
      Compresses buffer 'src' into buffer 'dst' with dictionary.
    • compressUsingDict

      public static byte[] compressUsingDict(byte[] src, byte[] dict, int level) throws ZstdException
      Compresses buffer 'src' with dictionary.
      Parameters:
      src - the source buffer
      dict - the dictionary buffer
      level - compression level
      Returns:
      compressed byte array
      Throws:
      ZstdException
    • compress

      public static long compress(byte[] dst, byte[] src, byte[] dict, int level)
      Compresses buffer 'src' into buffer 'dst' with dictionary. 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:
      dst - the destination buffer
      src - the source buffer
      dict - the dictionary buffer
      level - compression level
      Returns:
      the number of bytes written into buffer 'dst' or an error code if it fails (which can be tested using ZSTD_isError())
    • compress

      public static int compress(ByteBuffer dstBuff, ByteBuffer srcBuff, byte[] dict, int level) throws ZstdException
      Compresses buffer 'src' into buffer 'dst' with dictionary. 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
      srcBuff - the source buffer
      dict - the dictionary buffer
      level - compression level
      Returns:
      the number of bytes written into buffer 'dstBuff'
      Throws:
      ZstdException
    • compress

      public static ByteBuffer compress(ByteBuffer srcBuff, byte[] dict, int level) throws ZstdException
      Compresses buffer 'src' into buffer 'dst' with dictionary. 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:
      srcBuff - the source buffer
      dict - the dictionary buffer
      level - compression level
      Returns:
      compressed direct byte buffer
      Throws:
      ZstdException
    • compress

      public static int compress(ByteBuffer dstBuff, ByteBuffer srcBuff, ZstdDictCompress dict) throws ZstdException
      Compresses buffer 'src' into buffer 'dst' with dictionary. 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
      srcBuff - the source buffer
      dict - the dictionary buffer
      Returns:
      the number of bytes written into buffer 'dstBuff'
      Throws:
      ZstdException
    • compress

      public static ByteBuffer compress(ByteBuffer srcBuff, ZstdDictCompress dict) throws ZstdException
      Compresses buffer 'src' into buffer 'dst' with dictionary. 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:
      srcBuff - the source buffer
      dict - the dictionary buffer
      Returns:
      compressed direct byte buffer
      Throws:
      ZstdException
    • decompress

      public static byte[] decompress(byte[] src, int originalSize) throws ZstdException
      Decompress data
      Parameters:
      src - the source buffer
      originalSize - the maximum size of the uncompressed data
      Returns:
      byte array with the decompressed data
      Throws:
      ZstdException
    • decompress

      public static int decompress(ByteBuffer dstBuf, ByteBuffer srcBuf) throws ZstdException
      Decompress data
      Parameters:
      dstBuf - the destination buffer. must be direct. It is assumed that the position() of this buffer marks the offset at which the decompressed data are to be written, and that the limit() of this buffer is the maximum decompressed data size to allow.

      When this method returns successfully, dstBuf's position() will be set to its current position() plus the decompressed 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 compressed data to be decompressed, and that the limit() of this buffer marks its end.

      When this method returns successfully, srcBuf's position() will be set to its limit().

      Returns:
      the size of the decompressed data.
      Throws:
      ZstdException
    • decompress

      public static ByteBuffer decompress(ByteBuffer srcBuf, int originalSize) throws ZstdException
      Decompress data
      Parameters:
      srcBuf - the source buffer. must be direct. It is assumed that the position() of this buffer marks the beginning of the compressed data to be decompressed, and that the limit() of this buffer marks its end.

      When this method returns successfully, srcBuf's position() will be set to its limit().

      originalSize - the maximum size of the uncompressed data
      Returns:
      A newly-allocated ByteBuffer containing the decompressed data. The position() of this buffer will be 0, and the limit() will be the size of the decompressed data. In other words the buffer is ready to be used for reading. Note that this is different behavior from the other decompress() overload which takes as a parameter the destination ByteBuffer.
      Throws:
      ZstdException
    • decompress

      public static byte[] decompress(byte[] src, ZstdDictDecompress dict, int originalSize) throws ZstdException
      Decompress data
      Parameters:
      src - the source buffer
      dict - dictionary to use
      originalSize - the maximum size of the uncompressed data
      Returns:
      byte array with the decompressed data
      Throws:
      ZstdException
    • decompressUsingDict

      @Deprecated public static long decompressUsingDict(byte[] dst, byte[] src, byte[] dict)
      Deprecated.
      Use decompress(dst, src, dict) instead
      Decompresses buffer 'src' into buffer 'dst' with dictionary.
    • decompress

      public static long decompress(byte[] dst, byte[] src, byte[] dict)
      Decompresses buffer 'src' into buffer 'dst' with dictionary. Destination buffer should be sized to be larger of equal to the originalSize
      Parameters:
      dst - the destination buffer
      src - the source buffer
      dict - the dictionary buffer
      Returns:
      the number of bytes decompressed into destination buffer (originalSize) or an errorCode if it fails (which can be tested using ZSTD_isError())
    • decompress

      public static byte[] decompress(byte[] src, byte[] dict, int originalSize) throws ZstdException
      Parameters:
      src - the source buffer
      dict - dictionary to use
      originalSize - the maximum size of the uncompressed data
      Returns:
      byte array with the decompressed data
      Throws:
      ZstdException
    • decompressedSize

      public static long decompressedSize(ByteBuffer srcBuf)
      Return the original size of a compressed buffer (if known)
      Parameters:
      srcBuf - the compressed buffer. must be direct. It is assumed that the position() of this buffer marks the beginning of the compressed data whose decompressed size is being queried, and that the limit() of this buffer marks its end.
      Returns:
      the number of bytes of the original buffer 0 if the original size is not known
    • decompress

      public static int decompress(ByteBuffer dstBuff, ByteBuffer srcBuff, byte[] dict) throws ZstdException
      Decompress data
      Parameters:
      dstBuff - the destination buffer. must be direct. It is assumed that the position() of this buffer marks the offset at which the decompressed data are to be written, and that the limit() of this buffer is the maximum decompressed data size to allow.

      When this method returns successfully, dstBuff's position() will be set to its current position() plus the decompressed size of the data.

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

      When this method returns successfully, srcBuff's position() will be set to its limit().

      dict - the dictionary buffer to use for compression
      Returns:
      the size of the decompressed data.
      Throws:
      ZstdException
    • decompress

      public static ByteBuffer decompress(ByteBuffer srcBuff, byte[] dict, int originalSize) throws ZstdException
      Decompress data
      Parameters:
      srcBuff - the source buffer. must be direct. It is assumed that the position() of this buffer marks the beginning of the compressed data to be decompressed, and that the limit() of this buffer marks its end.

      When this method returns successfully, srcBuff's position() will be set to its limit().

      dict - the dictionary used in the compression
      originalSize - the maximum size of the uncompressed data
      Returns:
      A newly-allocated ByteBuffer containing the decompressed data. The position() of this buffer will be 0, and the limit() will be the size of the decompressed data. In other words the buffer is ready to be used for reading. Note that this is different behavior from the other decompress() overload which takes as a parameter the destination ByteBuffer.
      Throws:
      ZstdException
    • decompress

      public static int decompress(ByteBuffer dstBuff, ByteBuffer srcBuff, ZstdDictDecompress dict) throws ZstdException
      Decompress data
      Parameters:
      dstBuff - the destination buffer. must be direct. It is assumed that the position() of this buffer marks the offset at which the decompressed data are to be written, and that the limit() of this buffer is the maximum decompressed data size to allow.

      When this method returns successfully, dstBuff's position() will be set to its current position() plus the decompressed size of the data.

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

      When this method returns successfully, srcBuff's position() will be set to its limit().

      dict - the dictionary buffer to use for compression
      Returns:
      the size of the decompressed data.
      Throws:
      ZstdException
    • decompress

      public static ByteBuffer decompress(ByteBuffer srcBuff, ZstdDictDecompress dict, int originalSize) throws ZstdException
      Decompress data
      Parameters:
      srcBuff - the source buffer. must be direct. It is assumed that the position() of this buffer marks the beginning of the compressed data to be decompressed, and that the limit() of this buffer marks its end.

      When this method returns successfully, srcBuff's position() will be set to its limit().

      dict - the dictionary used in the compression
      originalSize - the maximum size of the uncompressed data
      Returns:
      A newly-allocated ByteBuffer containing the decompressed data. The position() of this buffer will be 0, and the limit() will be the size of the decompressed data. In other words the buffer is ready to be used for reading. Note that this is different behavior from the other decompress() overload which takes as a parameter the destination ByteBuffer.
      Throws:
      ZstdException
    • extractArray

      static final byte[] extractArray(ByteBuffer buffer)