public class ByteArrayDecoder extends MessageToMessageDecoder<ByteBuf,byte[]>
ByteBuf into an array of bytes.
A typical setup for TCP/IP would be:
and then you can use an array of bytes instead of aChannelPipelinepipeline = ...; // Decoders pipeline.addLast("frameDecoder", newLengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4)); pipeline.addLast("bytesDecoder", newByteArrayDecoder()); // Encoder pipeline.addLast("frameEncoder", newLengthFieldPrepender(4)); pipeline.addLast("bytesEncoder", newByteArrayEncoder());
ByteBuf
as a message:
void messageReceived(ChannelHandlerContextctx,MessageEvente) { byte[] bytes = (byte[]) e.getMessage(); ... }
ChannelHandler.Sharable| Constructor and Description |
|---|
ByteArrayDecoder() |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
decode(ChannelHandlerContext ctx,
ByteBuf msg) |
boolean |
isDecodable(Object msg)
Returns
true if and only if the specified message can be decoded by this decoder. |
inboundBufferUpdated, newInboundBufferafterAdd, afterRemove, beforeAdd, beforeRemove, channelActive, channelInactive, channelRegistered, channelUnregistered, exceptionCaught, userEventTriggeredclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitchannelActive, channelInactive, channelRegistered, channelUnregisteredafterAdd, afterRemove, beforeAdd, beforeRemove, exceptionCaught, userEventTriggeredpublic boolean isDecodable(Object msg) throws Exception
MessageToMessageDecodertrue if and only if the specified message can be decoded by this decoder.isDecodable in class MessageToMessageDecoder<ByteBuf,byte[]>msg - the messageExceptionpublic byte[] decode(ChannelHandlerContext ctx, ByteBuf msg) throws Exception
decode in class MessageToMessageDecoder<ByteBuf,byte[]>ExceptionCopyright © 2008-2012 The Netty Project. All Rights Reserved.