Class ObjectDecoder
- java.lang.Object
-
- org.jboss.netty.channel.SimpleChannelUpstreamHandler
-
- org.jboss.netty.handler.codec.frame.FrameDecoder
-
- org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder
-
- org.jboss.netty.handler.codec.serialization.ObjectDecoder
-
- All Implemented Interfaces:
ChannelHandler,ChannelUpstreamHandler,LifeCycleAwareChannelHandler
public class ObjectDecoder extends LengthFieldBasedFrameDecoder
A decoder which deserializes the receivedChannelBuffers into Java objects.Please note that the serialized form this decoder expects is not compatible with the standard
ObjectOutputStream. Please useObjectEncoderorObjectEncoderOutputStreamto ensure the interoperability with this decoder.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description private ClassResolverclassResolver-
Fields inherited from class org.jboss.netty.handler.codec.frame.FrameDecoder
cumulation, DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS
-
-
Constructor Summary
Constructors Constructor Description ObjectDecoder(int maxObjectSize, ClassResolver classResolver)Creates a new decoder with the specified maximum object size.ObjectDecoder(ClassResolver classResolver)Creates a new decoder whose maximum object size is1048576bytes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Objectdecode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer)Decodes the received packets so far into a frame.protected ChannelBufferextractFrame(ChannelBuffer buffer, int index, int length)Extract a Frame of the specified buffer.-
Methods inherited from class org.jboss.netty.handler.codec.frame.FrameDecoder
actualReadableBytes, afterAdd, afterRemove, appendToCumulation, beforeAdd, beforeRemove, channelClosed, channelDisconnected, cleanup, decodeLast, exceptionCaught, getMaxCumulationBufferCapacity, getMaxCumulationBufferComponents, internalBuffer, isUnfold, messageReceived, newCumulationBuffer, replace, setMaxCumulationBufferCapacity, setMaxCumulationBufferComponents, setUnfold, unfoldAndFireMessageReceived, updateCumulation
-
Methods inherited from class org.jboss.netty.channel.SimpleChannelUpstreamHandler
channelBound, channelConnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, handleUpstream, writeComplete
-
-
-
-
Field Detail
-
classResolver
private final ClassResolver classResolver
-
-
Constructor Detail
-
ObjectDecoder
public ObjectDecoder(ClassResolver classResolver)
Creates a new decoder whose maximum object size is1048576bytes. If the size of the received object is greater than1048576bytes, aStreamCorruptedExceptionwill be raised.- Parameters:
classResolver- theClassResolverto use for this decoder
-
ObjectDecoder
public ObjectDecoder(int maxObjectSize, ClassResolver classResolver)Creates a new decoder with the specified maximum object size.- Parameters:
maxObjectSize- the maximum byte length of the serialized object. if the length of the received object is greater than this value,StreamCorruptedExceptionwill be raised.classResolver- theClassResolverwhich will load the class of the serialized object
-
-
Method Detail
-
decode
protected java.lang.Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws java.lang.Exception
Description copied from class:FrameDecoderDecodes the received packets so far into a frame. If an sub-class wants to extract a frame out of the buffer it should use theFrameDecoder.extractFrame(ChannelBuffer, int, int)method, to make optimizations easier later.- Overrides:
decodein classLengthFieldBasedFrameDecoder- Parameters:
ctx- the context of this handlerchannel- the current channelbuffer- the cumulative buffer of received packets so far. Note that the buffer might be empty, which means you should not make an assumption that the buffer contains at least one byte in your decoder implementation.- Returns:
- the decoded frame if a full frame was received and decoded.
nullif there's not enough data in the buffer to decode a frame. - Throws:
java.lang.Exception
-
extractFrame
protected ChannelBuffer extractFrame(ChannelBuffer buffer, int index, int length)
Description copied from class:FrameDecoderExtract a Frame of the specified buffer. By default this implementation will return a extract the sub-region of the buffer and create a new one. If an sub-class want to extract a frame from the buffer it should use this method by default. Be sure that this method MUST not modify the readerIndex of the given buffer- Overrides:
extractFramein classFrameDecoder
-
-