public class ObjectDecoder extends LengthFieldBasedFrameDecoder
ByteBuf解串行化为Java对象。
请注意,此解码器预期的序列化格式与标准ObjectOutputStream不兼容。 请使用ObjectEncoder或ObjectEncoderOutputStream以确保与此解码器的互操作性。
ByteToMessageDecoder.CumulatorChannelHandler.SharableCOMPOSITE_CUMULATOR, MERGE_CUMULATOR| Constructor and Description |
|---|
ObjectDecoder(ClassResolver classResolver)
创建一个新的解码器,其最大对象大小为
1048576字节。
|
ObjectDecoder(int maxObjectSize, ClassResolver classResolver)
用指定的最大对象大小创建一个新的解码器。
|
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.Object |
decode(ChannelHandlerContext ctx, ByteBuf in)
从 ByteBuf中创建一个框架并将其返回。
|
decode, extractFrame, getUnadjustedFrameLengthactualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggeredchannelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaughtensureNotSharable, handlerAdded, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerAddedpublic ObjectDecoder(ClassResolver classResolver)
1048576字节。
如果接收到的对象的大小大于1048576字节,则会引发StreamCorruptedException 。
classResolver - 用于此解码器的ClassResolver
public ObjectDecoder(int maxObjectSize,
ClassResolver classResolver)
maxObjectSize - 序列化对象的最大字节长度。
如果接收到的对象的长度大于此值,则会引发StreamCorruptedException 。
classResolver - 将加载序列化对象的类的ClassResolver
protected java.lang.Object decode(ChannelHandlerContext ctx, ByteBuf in) throws java.lang.Exception
LengthFieldBasedFrameDecoder
ByteBuf中创建一个框架并将其返回。
decode在课堂上
LengthFieldBasedFrameDecoder
ctx - 这ByteToMessageDecoder所属的ChannelHandlerContext
in - 从中读取数据的ByteBuf
ByteBuf代表帧或null 。
java.lang.Exception
Copyright © 2008–2018 The Netty Project. All rights reserved.