@ChannelHandler.Sharable public final class BrotliEncoder extends MessageToByteEncoder<ByteBuf>
ChannelHandler.Sharable| Constructor and Description |
|---|
BrotliEncoder()
|
BrotliEncoder(BrotliOptions brotliOptions)
Create a new
BrotliEncoder Instance |
BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters)
|
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. |
| Modifier and Type | Method and Description |
|---|---|
protected ByteBuf |
allocateBuffer(ChannelHandlerContext ctx,
ByteBuf msg,
boolean preferDirect)
Allocate a
ByteBuf which will be used as argument of #encode(ChannelHandlerContext, I, ByteBuf). |
void |
close(ChannelHandlerContext ctx,
ChannelPromise promise)
Calls
ChannelOutboundInvoker.close(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
protected void |
encode(ChannelHandlerContext ctx,
ByteBuf msg,
ByteBuf out)
Encode a message into a
ByteBuf. |
void |
finish(ChannelHandlerContext ctx)
Finish the encoding, close streams and write final
ByteBuf to the channel. |
void |
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
void |
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
boolean |
isSharable()
|
acceptOutboundMessage, isPreferDirect, writebind, connect, deregister, disconnect, flush, readensureNotSharable, exceptionCaughtclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaughtpublic BrotliEncoder()
public BrotliEncoder(BrotliOptions brotliOptions)
BrotliEncoder InstancebrotliOptions - BrotliOptions to use and
isSharable() set to truepublic BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters)
parameters - Encoder.Parameters to usepublic 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.
isSharable() is true then on handlerAdded(ChannelHandlerContext) call,
a new 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 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 - Encoder.Parameters to useisSharable - Set to true if this instance is shared else set to falsepublic void handlerAdded(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterhandlerAdded in interface ChannelHandlerhandlerAdded in class ChannelHandlerAdapterExceptionpublic void handlerRemoved(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterhandlerRemoved in interface ChannelHandlerhandlerRemoved in class ChannelHandlerAdapterExceptionprotected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception
MessageToByteEncoderByteBuf. This method will be called for each written message that can be handled
by this encoder.encode in class MessageToByteEncoder<ByteBuf>ctx - the ChannelHandlerContext which this MessageToByteEncoder belongs tomsg - the message to encodeout - the ByteBuf into which the encoded message will be writtenException - is thrown if an error occursprotected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws Exception
MessageToByteEncoderByteBuf which will be used as argument of #encode(ChannelHandlerContext, I, ByteBuf).
Sub-classes may override this method to return ByteBuf with a perfect matching initialCapacity.allocateBuffer in class MessageToByteEncoder<ByteBuf>Exceptionpublic boolean isSharable()
ChannelHandlerAdapterisSharable in class ChannelHandlerAdapterpublic void finish(ChannelHandlerContext ctx) throws IOException
ByteBuf to the channel.ctx - ChannelHandlerContext which we want to closeIOException - If an error occurred during closurepublic void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
ChannelOutboundHandlerAdapterChannelOutboundInvoker.close(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.close in interface ChannelOutboundHandlerclose in class ChannelOutboundHandlerAdapterctx - the ChannelHandlerContext for which the close operation is madepromise - the ChannelPromise to notify once the operation completesException - thrown if an error occursCopyright © 2008–2025 The Netty Project. All rights reserved.