Class BrotliEncoder
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelOutboundHandlerAdapter
-
- io.netty.handler.codec.MessageToByteEncoder<ByteBuf>
-
- io.netty.handler.codec.compression.BrotliEncoder
-
- All Implemented Interfaces:
ChannelHandler,ChannelOutboundHandler
@Sharable public final class BrotliEncoder extends MessageToByteEncoder<ByteBuf>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Constructor Description BrotliEncoder()BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters)BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters, boolean isSharable)Create a newBrotliEncoderInstance and specify whether this instance will be shared with multiple pipelines or not.BrotliEncoder(BrotliOptions brotliOptions)Create a newBrotliEncoderInstance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ByteBufallocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect)Allocate aByteBufwhich will be used as argument of#encode(ChannelHandlerContext, I, ByteBuf).voidclose(ChannelHandlerContext ctx, ChannelPromise promise)CallsChannelOutboundInvoker.close(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.protected voidencode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out)Encode a message into aByteBuf.voidfinish(ChannelHandlerContext ctx)Finish the encoding, close streams and write finalByteBufto the channel.voidhandlerAdded(ChannelHandlerContext ctx)Do nothing by default, sub-classes may override this method.voidhandlerRemoved(ChannelHandlerContext ctx)Do nothing by default, sub-classes may override this method.booleanisSharable()Returntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.-
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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.ChannelHandler
exceptionCaught
-
-
-
-
Constructor Detail
-
BrotliEncoder
public BrotliEncoder()
-
BrotliEncoder
public BrotliEncoder(BrotliOptions brotliOptions)
Create a newBrotliEncoderInstance- Parameters:
brotliOptions-BrotliOptionsto use andisSharable()set totrue
-
BrotliEncoder
public BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters)
- Parameters:
parameters-Encoder.Parametersto use
-
BrotliEncoder
public BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters, boolean isSharable)Create a new
IfBrotliEncoderInstance and specify whether this instance will be shared with multiple pipelines or not.isSharable()is true then onhandlerAdded(ChannelHandlerContext)call, a newBrotliEncoder.Writerwill create, and it will be mapped usingAttributeMap.attr(AttributeKey)soBrotliEncodercan be shared with multiple pipelines. This works fine but there on everyencode(ChannelHandlerContext, ByteBuf, ByteBuf)call, we have to get theBrotliEncoder.Writerassociated with the appropriate channel. And this will add a overhead. So it is recommended to setisSharable()tofalseand create newBrotliEncoderinstance for every pipeline.- Parameters:
parameters-Encoder.Parametersto useisSharable- Set totrueif this instance is shared else set tofalse
-
-
Method Detail
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
java.lang.Exception
-
handlerRemoved
public void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerRemovedin interfaceChannelHandler- Overrides:
handlerRemovedin classChannelHandlerAdapter- Throws:
java.lang.Exception
-
encode
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws java.lang.Exception
Description copied from class:MessageToByteEncoderEncode a message into aByteBuf. This method will be called for each written message that can be handled by this encoder.- Specified by:
encodein classMessageToByteEncoder<ByteBuf>- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToByteEncoderbelongs tomsg- the message to encodeout- theByteBufinto which the encoded message will be written- Throws:
java.lang.Exception- is thrown if an error occurs
-
allocateBuffer
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws java.lang.Exception
Description copied from class:MessageToByteEncoderAllocate aByteBufwhich will be used as argument of#encode(ChannelHandlerContext, I, ByteBuf). Sub-classes may override this method to returnByteBufwith a perfect matchinginitialCapacity.- Overrides:
allocateBufferin classMessageToByteEncoder<ByteBuf>- Throws:
java.lang.Exception
-
isSharable
public boolean isSharable()
Description copied from class:ChannelHandlerAdapterReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.- Overrides:
isSharablein classChannelHandlerAdapter
-
finish
public void finish(ChannelHandlerContext ctx) throws java.io.IOException
Finish the encoding, close streams and write finalByteBufto the channel.- Parameters:
ctx-ChannelHandlerContextwhich we want to close- Throws:
java.io.IOException- If an error occurred during closure
-
close
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
Description copied from class:ChannelOutboundHandlerAdapterCallsChannelOutboundInvoker.close(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
closein interfaceChannelOutboundHandler- Overrides:
closein classChannelOutboundHandlerAdapter- Parameters:
ctx- theChannelHandlerContextfor which the close operation is madepromise- theChannelPromiseto notify once the operation completes- Throws:
java.lang.Exception- thrown if an error occurs
-
-