public abstract class MessageToByteEncoder<I>
extends io.netty.channel.ChannelOutboundMessageHandlerAdapter<I>
ChannelOutboundMessageHandlerAdapter
which encodes message in a stream-like fashion from one message to an
ByteBuf
.
Example implementation which encodes Integer
s to a ByteBuf
.
public class IntegerEncoder extendsMessageToByteEncoder
<Integer
> {@Override
public void encode(ChannelHandlerContext
ctx,Integer
msg,ByteBuf
out) throwsException
{ out.writeInt(msg); } }
Modifier | Constructor and Description |
---|---|
protected |
MessageToByteEncoder() |
protected |
MessageToByteEncoder(Class<? extends I> outboundMessageType) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
encode(io.netty.channel.ChannelHandlerContext ctx,
I msg,
io.netty.buffer.ByteBuf out)
Encode a message into a
ByteBuf . |
void |
flush(io.netty.channel.ChannelHandlerContext ctx,
I msg) |
acceptOutboundMessage, beginFlush, endFlush, flush, isCloseOnFailedFlush, newOutboundBuffer, setCloseOnFailedFlush
bind, close, connect, deregister, disconnect, read, sendFile
exceptionCaught, handlerAdded, handlerRemoved
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public void flush(io.netty.channel.ChannelHandlerContext ctx, I msg) throws Exception
Exception
protected abstract void encode(io.netty.channel.ChannelHandlerContext ctx, I msg, io.netty.buffer.ByteBuf out) throws Exception
ByteBuf
. This method will be called till the MessageBuf
has
nothing left.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 accourCopyright © 2008-2013 The Netty Project. All Rights Reserved.