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
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionBrotliEncoder(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
Modifier and TypeMethodDescriptionprotected ByteBufallocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) Allocate aByteBufwhich will be used as argument ofMessageToByteEncoder.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.voidDo nothing by default, sub-classes may override this method.voidDo nothing by default, sub-classes may override this method.booleanReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.Methods inherited from class MessageToByteEncoder
acceptOutboundMessage, isPreferDirect, writeMethods inherited from class ChannelOutboundHandlerAdapter
bind, connect, deregister, disconnect, flush, readMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, exceptionCaughtMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChannelHandler
exceptionCaught
-
Constructor Details
-
BrotliEncoder
public BrotliEncoder() -
BrotliEncoder
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 Details
-
handlerAdded
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
Exception
-
handlerRemoved
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerRemovedin interfaceChannelHandler- Overrides:
handlerRemovedin classChannelHandlerAdapter- Throws:
Exception
-
encode
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:
Exception- is thrown if an error occurs
-
allocateBuffer
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws Exception Description copied from class:MessageToByteEncoderAllocate aByteBufwhich will be used as argument ofMessageToByteEncoder.encode(ChannelHandlerContext, I, ByteBuf). Sub-classes may override this method to returnByteBufwith a perfect matchinginitialCapacity.- Overrides:
allocateBufferin classMessageToByteEncoder<ByteBuf>- Throws:
Exception
-
isSharable
public boolean isSharable()Description copied from class:ChannelHandlerAdapterReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.- Overrides:
isSharablein classChannelHandlerAdapter
-
finish
Finish the encoding, close streams and write finalByteBufto the channel.- Parameters:
ctx-ChannelHandlerContextwhich we want to close- Throws:
IOException- If an error occurred during closure
-
close
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:
Exception- thrown if an error occurs
-