Class BrotliEncoder

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

    @Sharable
    public final class BrotliEncoder
    extends io.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>
    Compress a ByteBuf with the Brotli compression.

    See brotli.

    • Nested Class Summary

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

        io.netty.channel.ChannelHandler.Sharable
    • 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)  
      void close​(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)  
      protected void encode​(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, io.netty.buffer.ByteBuf out)  
      void finish​(io.netty.channel.ChannelHandlerContext ctx)
      Finish the encoding, close streams and write final ByteBuf to the channel.
      void handlerAdded​(io.netty.channel.ChannelHandlerContext ctx)  
      void handlerRemoved​(io.netty.channel.ChannelHandlerContext ctx)  
      boolean isSharable()  
      • 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
      • Methods inherited from interface io.netty.channel.ChannelHandler

        exceptionCaught
    • Constructor Detail

      • BrotliEncoder

        public BrotliEncoder()
        Create a new BrotliEncoder Instance with BrotliOptions.DEFAULT and isSharable() set to true
      • BrotliEncoder

        public BrotliEncoder​(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters)
        Create a new BrotliEncoder Instance and isSharable() set to true
        Parameters:
        parameters - Encoder.Parameters to use
      • BrotliEncoder

        public BrotliEncoder​(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters,
                             boolean isSharable)

        Create a new BrotliEncoder Instance and specify whether this instance will be shared with multiple pipelines or not.

        If isSharable() is true then on handlerAdded(ChannelHandlerContext) call, a new BrotliEncoder.Writer will create, and it will be mapped using AttributeMap.attr(AttributeKey) so BrotliEncoder can be shared with multiple pipelines. This works fine but there on every encode(ChannelHandlerContext, ByteBuf, ByteBuf) call, we have to get the BrotliEncoder.Writer associated with the appropriate channel. And this will add a overhead. So it is recommended to set isSharable() to false and create new BrotliEncoder instance for every pipeline.
        Parameters:
        parameters - Encoder.Parameters to use
        isSharable - Set to true if this instance is shared else set to false
    • Method Detail

      • 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
      • handlerRemoved

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

        protected void encode​(io.netty.channel.ChannelHandlerContext ctx,
                              io.netty.buffer.ByteBuf msg,
                              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 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
      • isSharable

        public boolean isSharable()
        Overrides:
        isSharable in class io.netty.channel.ChannelHandlerAdapter
      • finish

        public void finish​(io.netty.channel.ChannelHandlerContext ctx)
                    throws IOException
        Finish the encoding, close streams and write final ByteBuf to the channel.
        Parameters:
        ctx - ChannelHandlerContext which we want to close
        Throws:
        IOException - If an error occurred during closure
      • 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