Class BrotliEncoder
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelOutboundHandlerAdapter
-
- io.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>
-
- io.netty.handler.codec.compression.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 aByteBufwith the Brotli compression.See brotli.
-
-
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 io.netty.buffer.ByteBufallocateBuffer(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, boolean preferDirect)voidclose(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)protected voidencode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, io.netty.buffer.ByteBuf out)voidfinish(io.netty.channel.ChannelHandlerContext ctx)Finish the encoding, close streams and write finalByteBufto the channel.voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx)voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx)booleanisSharable()-
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
-
-
-
-
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(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerRemovedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerRemovedin classio.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:
encodein classio.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:
allocateBufferin classio.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>- Throws:
Exception
-
isSharable
public boolean isSharable()
- Overrides:
isSharablein classio.netty.channel.ChannelHandlerAdapter
-
finish
public void finish(io.netty.channel.ChannelHandlerContext ctx) throws IOExceptionFinish the encoding, close streams and write finalByteBufto the channel.- Parameters:
ctx-ChannelHandlerContextwhich we want to close- Throws:
IOException- If an error occurred during closure
-
-