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 Integer
s from
the input ByteBuf
and square them before write them to the output ByteBuf
.
public class SquareEncoder extendsByteToByteEncoder
{@Override
public void encode(ChannelHandlerContext
ctx,ByteBuf
in,ByteBuf
out) throwsException
{ 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) |
void |
sendFile(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.FileRegion region,
io.netty.channel.ChannelPromise promise) |
discardOutboundReadBytes, flush, newOutboundBuffer
bind, close, connect, deregister, disconnect, read
exceptionCaught, handlerAdded, handlerRemoved
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
protected 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.ChannelOutboundByteHandlerAdapter
Exception
public void sendFile(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.FileRegion region, io.netty.channel.ChannelPromise promise) throws Exception
sendFile
in interface io.netty.channel.ChannelOperationHandler
sendFile
in class io.netty.channel.ChannelOperationHandlerAdapter
Exception
protected 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.