Class ZlibCompressor

    • Method Detail

      • newFactory

        public static Supplier<ZlibCompressor> newFactory​(int compressionLevel)
        Creates a zlib compressor factory with the specified compressionLevel and the default wrapper (ZlibWrapper.ZLIB).
        Parameters:
        compressionLevel - 1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
        Throws:
        CompressionException - if failed to initialize zlib
      • newFactory

        public static Supplier<ZlibCompressor> newFactory​(ZlibWrapper wrapper)
        Creates a zlib compressor factory with the default compression level (6) and the specified wrapper.
        Returns:
        the factory.
        Throws:
        CompressionException - if failed to initialize zlib
      • newFactory

        public static Supplier<ZlibCompressor> newFactory​(ZlibWrapper wrapper,
                                                          int compressionLevel)
        Creates a zlib compressor factory with the specified compressionLevel and the specified wrapper.
        Parameters:
        compressionLevel - 1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
        Returns:
        the factory.
        Throws:
        CompressionException - if failed to initialize zlib
      • newFactory

        public static Supplier<ZlibCompressor> newFactory​(byte[] dictionary)
        Creates a zlib compressor factory with the default compression level (6) and the specified preset dictionary. The wrapper is always ZlibWrapper.ZLIB because it is the only format that supports the preset dictionary.
        Parameters:
        dictionary - the preset dictionary
        Returns:
        the factory.
        Throws:
        CompressionException - if failed to initialize zlib
      • newFactory

        public static Supplier<ZlibCompressor> newFactory​(int compressionLevel,
                                                          byte[] dictionary)
        Creates a zlib compressor factory with the specified compressionLevel and the specified preset dictionary. The wrapper is always ZlibWrapper.ZLIB because it is the only format that supports the preset dictionary.
        Parameters:
        compressionLevel - 1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
        dictionary - the preset dictionary
        Returns:
        the factory.
        Throws:
        CompressionException - if failed to initialize zlib
      • compress

        public Buffer compress​(Buffer uncompressed,
                               BufferAllocator allocator)
                        throws CompressionException
        Description copied from interface: Compressor
        This method will read from the input Buffer and compress into a new Buffer that will be allocated (if needed) from the BufferAllocator. This method is expected to consume all data from the input but not take ownership. The caller is responsible to release the input buffer after this method returns.
        Specified by:
        compress in interface Compressor
        Parameters:
        uncompressed - the Buffer that contains the data to be compressed.
        allocator - the BufferAllocator that is used to allocate a new buffer (if needed) to write the compressed bytes too.
        Returns:
        the Buffer that contains the compressed data. The caller of this method takes ownership of the buffer. The return value will never be null.
        Throws:
        CompressionException - thrown if an compression error was encountered or the compressor was closed already.
      • finish

        public Buffer finish​(BufferAllocator allocator)
        Description copied from interface: Compressor
        By calling this method we signal that the compression stream is marked as finish. The returned Buffer might contain a "trailer" which marks the end of the stream.
        Specified by:
        finish in interface Compressor
        Returns:
        the Buffer which represent the end of the compression stream, which might be empty if the compressor don't need a trailer to signal the end. The caller of this method takes ownership of the buffer. The return value will never be null.
      • isClosed

        public boolean isClosed()
        Description copied from interface: Compressor
        Return true if the decompressor was closed, false otherwise.
        Specified by:
        isClosed in interface Compressor
        Returns:
        true if the decompressor was closed, false otherwise.