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
A decoder which deserializes the received
ChannelBuffer
s into Java
objects.
Please note that the serialized form this decoder expects is not
compatible with the standard ObjectOutputStream
. Please use
ObjectEncoder
or ObjectEncoderOutputStream
to ensure the
interoperability with this decoder.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsFields inherited from class org.jboss.netty.handler.codec.frame.FrameDecoder
cumulation, DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS
-
Constructor Summary
ConstructorsConstructorDescriptionObjectDecoder
(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 is1048576
bytes. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
decode
(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) Decodes the received packets so far into a frame.protected ChannelBuffer
extractFrame
(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 Details
-
classResolver
-
-
Constructor Details
-
ObjectDecoder
Creates a new decoder whose maximum object size is1048576
bytes. If the size of the received object is greater than1048576
bytes, aStreamCorruptedException
will be raised.- Parameters:
classResolver
- theClassResolver
to use for this decoder
-
ObjectDecoder
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,StreamCorruptedException
will be raised.classResolver
- theClassResolver
which will load the class of the serialized object
-
-
Method Details
-
decode
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception Description copied from class:FrameDecoder
Decodes 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:
decode
in 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.
null
if there's not enough data in the buffer to decode a frame. - Throws:
Exception
-
extractFrame
Description copied from class:FrameDecoder
Extract 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:
extractFrame
in classFrameDecoder
-