public abstract class ByteToByteEncoder
extends io.netty.channel.ChannelOutboundByteHandlerAdapter
ChannelOutboundByteHandlerAdapter which encodes bytes in a stream-like fashion from one ByteBuf to an
other.
This kind of decoder is often useful for doing on-the-fly processing like i.e. compression.
But you can also do other things with it. For example here is an implementation which reads Integers from
the input ByteBuf and square them before write them to the output ByteBuf.
public class SquareEncoder extends ByteToByteEncoder {
@Override
public void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out)
throws Exception {
if (in.readableBytes() < 4) {
return;
}
int value = in.readInt();
out.writeInt(value * value);
}
}
| Constructor and Description |
|---|
ByteToByteEncoder() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
encode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.buffer.ByteBuf out)
Encodes the from one
ByteBuf to an other. |
protected void |
flush(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.channel.ChannelPromise promise) |
discardOutboundReadBytes, flush, freeOutboundBuffer, newOutboundBufferbind, close, connect, deregister, disconnect, read, sendFileafterAdd, afterRemove, beforeAdd, beforeRemove, exceptionCaught, userEventTriggeredclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitprotected void flush(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.channel.ChannelPromise promise)
throws Exception
flush in class io.netty.channel.ChannelOutboundByteHandlerAdapterExceptionprotected abstract void encode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.buffer.ByteBuf out)
throws Exception
ByteBuf to an other. This method will be called till either the input
ByteBuf has nothing to read anymore or till nothing was read from the input ByteBuf.ctx - the ChannelHandlerContext which this ByteToByteDecoder belongs toin - the ByteBuf from which to read dataout - the ByteBuf to which the decoded data will be writtenException - is thrown if an error accourCopyright © 2008-2013 The Netty Project. All Rights Reserved.