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 newBrotliEncoder
Instance and specify whether this instance will be shared with multiple pipelines or not.BrotliEncoder(BrotliOptions brotliOptions)
Create a newBrotliEncoder
Instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ByteBuf
allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect)
Allocate aByteBuf
which will be used as argument of#encode(ChannelHandlerContext, I, ByteBuf)
.void
close(ChannelHandlerContext ctx, ChannelPromise promise)
CallsChannelOutboundInvoker.close(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
.protected void
encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out)
Encode a message into aByteBuf
.void
finish(ChannelHandlerContext ctx)
Finish the encoding, close streams and write finalByteBuf
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()
Returntrue
if the implementation isChannelHandler.Sharable
and so can be added to differentChannelPipeline
s.-
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 newBrotliEncoder
Instance- Parameters:
brotliOptions
-BrotliOptions
to use andisSharable()
set totrue
-
BrotliEncoder
public BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters)
- Parameters:
parameters
-Encoder.Parameters
to use
-
BrotliEncoder
public BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters, boolean isSharable)
Create a new
IfBrotliEncoder
Instance and specify whether this instance will be shared with multiple pipelines or not.isSharable()
is true then onhandlerAdded(ChannelHandlerContext)
call, a newBrotliEncoder.Writer
will create, and it will be mapped usingAttributeMap.attr(AttributeKey)
soBrotliEncoder
can be shared with multiple pipelines. This works fine but there on everyencode(ChannelHandlerContext, ByteBuf, ByteBuf)
call, we have to get theBrotliEncoder.Writer
associated with the appropriate channel. And this will add a overhead. So it is recommended to setisSharable()
tofalse
and create newBrotliEncoder
instance for every pipeline.- Parameters:
parameters
-Encoder.Parameters
to useisSharable
- Set totrue
if this instance is shared else set tofalse
-
-
Method Detail
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerAdded
in interfaceChannelHandler
- Overrides:
handlerAdded
in classChannelHandlerAdapter
- Throws:
java.lang.Exception
-
handlerRemoved
public void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerRemoved
in interfaceChannelHandler
- Overrides:
handlerRemoved
in classChannelHandlerAdapter
- Throws:
java.lang.Exception
-
encode
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws java.lang.Exception
Description copied from class:MessageToByteEncoder
Encode a message into aByteBuf
. This method will be called for each written message that can be handled by this encoder.- Specified by:
encode
in classMessageToByteEncoder<ByteBuf>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToByteEncoder
belongs tomsg
- the message to encodeout
- theByteBuf
into 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:MessageToByteEncoder
Allocate aByteBuf
which will be used as argument of#encode(ChannelHandlerContext, I, ByteBuf)
. Sub-classes may override this method to returnByteBuf
with a perfect matchinginitialCapacity
.- Overrides:
allocateBuffer
in classMessageToByteEncoder<ByteBuf>
- Throws:
java.lang.Exception
-
isSharable
public boolean isSharable()
Description copied from class:ChannelHandlerAdapter
Returntrue
if the implementation isChannelHandler.Sharable
and so can be added to differentChannelPipeline
s.- Overrides:
isSharable
in classChannelHandlerAdapter
-
finish
public void finish(ChannelHandlerContext ctx) throws java.io.IOException
Finish the encoding, close streams and write finalByteBuf
to the channel.- Parameters:
ctx
-ChannelHandlerContext
which 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:ChannelOutboundHandlerAdapter
CallsChannelOutboundInvoker.close(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
close
in interfaceChannelOutboundHandler
- Overrides:
close
in classChannelOutboundHandlerAdapter
- Parameters:
ctx
- theChannelHandlerContext
for which the close operation is madepromise
- theChannelPromise
to notify once the operation completes- Throws:
java.lang.Exception
- thrown if an error occurs
-
-