@ChannelHandler.Sharable public final class BrotliEncoder extends MessageToByteEncoder<io.netty.buffer.ByteBuf>
ByteBuf with the Brotli compression.
See brotli.
| 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 io.netty.buffer.ByteBuf |
allocateBuffer(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf msg,
boolean preferDirect)
Allocate a
ByteBuf which will be used as argument of #encode(ChannelHandlerContext, I, ByteBuf). |
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)
Encode a message into a
ByteBuf. |
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() |
acceptOutboundMessage, isPreferDirect, writebind, connect, deregister, disconnect, flush, readensureNotSharable, exceptionCaughtpublic 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(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
handlerAdded in interface io.netty.channel.ChannelHandlerhandlerAdded in class io.netty.channel.ChannelHandlerAdapterExceptionpublic void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
handlerRemoved in interface io.netty.channel.ChannelHandlerhandlerRemoved in class io.netty.channel.ChannelHandlerAdapterExceptionprotected void encode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf msg,
io.netty.buffer.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<io.netty.buffer.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 io.netty.buffer.ByteBuf allocateBuffer(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.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<io.netty.buffer.ByteBuf>Exceptionpublic boolean isSharable()
isSharable in class io.netty.channel.ChannelHandlerAdapterpublic void finish(io.netty.channel.ChannelHandlerContext ctx)
throws IOException
ByteBuf to the channel.ctx - ChannelHandlerContext which we want to closeIOException - If an error occurred during closureCopyright © 2008–2025 The Netty Project. All rights reserved.