Class JdkZlibEncoder

  • All Implemented Interfaces:
    io.netty.channel.ChannelHandler, io.netty.channel.ChannelOutboundHandler

    public class JdkZlibEncoder
    extends ZlibEncoder
    Compresses a ByteBuf using the deflate algorithm.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

        io.netty.channel.ChannelHandler.Sharable
    • Constructor Summary

      Constructors 
      Constructor Description
      JdkZlibEncoder()
      Creates a new zlib encoder with the default compression level (6) and the default wrapper (ZlibWrapper.ZLIB).
      JdkZlibEncoder​(byte[] dictionary)
      Creates a new zlib encoder with the default compression level (6) and the specified preset dictionary.
      JdkZlibEncoder​(int compressionLevel)
      Creates a new zlib encoder with the specified compressionLevel and the default wrapper (ZlibWrapper.ZLIB).
      JdkZlibEncoder​(int compressionLevel, byte[] dictionary)
      Creates a new zlib encoder with the specified compressionLevel and the specified preset dictionary.
      JdkZlibEncoder​(ZlibWrapper wrapper)
      Creates a new zlib encoder with the default compression level (6) and the specified wrapper.
      JdkZlibEncoder​(ZlibWrapper wrapper, int compressionLevel)
      Creates a new zlib encoder with the specified compressionLevel and the specified wrapper.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected io.netty.buffer.ByteBuf allocateBuffer​(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, boolean preferDirect)  
      io.netty.channel.ChannelFuture close()
      Close this ZlibEncoder and so finish the encoding.
      void close​(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)  
      io.netty.channel.ChannelFuture close​(io.netty.channel.ChannelPromise promise)
      Close this ZlibEncoder and so finish the encoding.
      protected void encode​(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf uncompressed, io.netty.buffer.ByteBuf out)  
      void handlerAdded​(io.netty.channel.ChannelHandlerContext ctx)  
      boolean isClosed()
      Returns true if and only if the end of the compressed stream has been reached.
      • Methods inherited from class io.netty.handler.codec.MessageToByteEncoder

        acceptOutboundMessage, isPreferDirect, write
      • Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter

        bind, connect, deregister, disconnect, flush, read
      • Methods inherited from class io.netty.channel.ChannelHandlerAdapter

        ensureNotSharable, exceptionCaught, handlerRemoved, isSharable
      • Methods inherited from interface io.netty.channel.ChannelHandler

        exceptionCaught, handlerRemoved
    • Constructor Detail

      • JdkZlibEncoder

        public JdkZlibEncoder()
        Creates a new zlib encoder with the default compression level (6) and the default wrapper (ZlibWrapper.ZLIB).
        Throws:
        CompressionException - if failed to initialize zlib
      • JdkZlibEncoder

        public JdkZlibEncoder​(int compressionLevel)
        Creates a new zlib encoder 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
      • JdkZlibEncoder

        public JdkZlibEncoder​(ZlibWrapper wrapper)
        Creates a new zlib encoder with the default compression level (6) and the specified wrapper.
        Throws:
        CompressionException - if failed to initialize zlib
      • JdkZlibEncoder

        public JdkZlibEncoder​(ZlibWrapper wrapper,
                              int compressionLevel)
        Creates a new zlib encoder 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.
        Throws:
        CompressionException - if failed to initialize zlib
      • JdkZlibEncoder

        public JdkZlibEncoder​(byte[] dictionary)
        Creates a new zlib encoder 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
        Throws:
        CompressionException - if failed to initialize zlib
      • JdkZlibEncoder

        public JdkZlibEncoder​(int compressionLevel,
                              byte[] dictionary)
        Creates a new zlib encoder 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
        Throws:
        CompressionException - if failed to initialize zlib
    • Method Detail

      • close

        public io.netty.channel.ChannelFuture close()
        Description copied from class: ZlibEncoder
        Close this ZlibEncoder and so finish the encoding. The returned ChannelFuture will be notified once the operation completes.
        Specified by:
        close in class ZlibEncoder
      • close

        public io.netty.channel.ChannelFuture close​(io.netty.channel.ChannelPromise promise)
        Description copied from class: ZlibEncoder
        Close this ZlibEncoder and so finish the encoding. The given ChannelFuture will be notified once the operation completes and will also be returned.
        Specified by:
        close in class ZlibEncoder
      • isClosed

        public boolean isClosed()
        Description copied from class: ZlibEncoder
        Returns true if and only if the end of the compressed stream has been reached.
        Specified by:
        isClosed in class ZlibEncoder
      • encode

        protected void encode​(io.netty.channel.ChannelHandlerContext ctx,
                              io.netty.buffer.ByteBuf uncompressed,
                              io.netty.buffer.ByteBuf out)
                       throws Exception
        Specified by:
        encode in class io.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>
        Throws:
        Exception
      • allocateBuffer

        protected final io.netty.buffer.ByteBuf allocateBuffer​(io.netty.channel.ChannelHandlerContext ctx,
                                                               io.netty.buffer.ByteBuf msg,
                                                               boolean preferDirect)
                                                        throws Exception
        Overrides:
        allocateBuffer in class io.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>
        Throws:
        Exception
      • close

        public void close​(io.netty.channel.ChannelHandlerContext ctx,
                          io.netty.channel.ChannelPromise promise)
                   throws Exception
        Specified by:
        close in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        close in class io.netty.channel.ChannelOutboundHandlerAdapter
        Throws:
        Exception
      • handlerAdded

        public void handlerAdded​(io.netty.channel.ChannelHandlerContext ctx)
                          throws Exception
        Specified by:
        handlerAdded in interface io.netty.channel.ChannelHandler
        Overrides:
        handlerAdded in class io.netty.channel.ChannelHandlerAdapter
        Throws:
        Exception