Top Description Constructors Methods
io.netty.handler.codec.bytes

public Class ByteArrayEncoder

extends MessageToMessageEncoder<byte[]>
Class Inheritance
Annotations
@Sharable
Imports
io.netty.buffer.ByteBuf, .Unpooled, io.netty.channel.ChannelHandler.Sharable, .ChannelHandlerContext, .ChannelPipeline, io.netty.handler.codec.LengthFieldBasedFrameDecoder, .LengthFieldPrepender, .MessageToMessageEncoder, java.util.List

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) {
    ...
}

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
encode(ChannelHandlerContext ctx, byte[]
the message to encode to an other one
msg
,
List<Object>
the List into which the encoded msg should be added needs to do some kind of aggregation
out
)

Implements abstract io.netty.handler.codec.MessageToMessageEncoder.encode.

Encode from one message to an other.
Inherited from io.netty.handler.codec.MessageToMessageEncoder:
acceptOutboundMessagewrite

Constructor Detail

ByteArrayEncoderback to summary
public ByteArrayEncoder()

Method Detail

encodeback to summary
protected void encode(ChannelHandlerContext ctx, byte[] msg, List<Object> out) throws Exception

Implements abstract io.netty.handler.codec.MessageToMessageEncoder.encode.

Doc from io.netty.handler.codec.MessageToMessageEncoder.encode.

Encode from one message to an other. This method will be called for each written message that can be handled by this encoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageEncoder belongs to

msg:byte[]

the message to encode to an other one

out:List<Object>

the List into which the encoded msg should be added needs to do some kind of aggregation

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs