Class ByteArrayEncoder

All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler

@Sharable public class ByteArrayEncoder extends MessageToMessageEncoder<byte[]>
Encodes the requested array of bytes into a ByteBuf. A typical setup for TCP/IP would be:
 ChannelPipeline pipeline = ...;

 // Decoders
 pipeline.addLast("frameDecoder",
                  new LengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4));
 pipeline.addLast("bytesDecoder",
                  new ByteArrayDecoder());

 // Encoder
 pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
 pipeline.addLast("bytesEncoder", new ByteArrayEncoder());
 
and then you can use an array of bytes instead of a ByteBuf as a message:
 void channelRead(ChannelHandlerContext ctx, byte[] bytes) {
     ...
 }