Class ObjectDecoder

All Implemented Interfaces:
ChannelHandler, ChannelUpstreamHandler, LifeCycleAwareChannelHandler

public class ObjectDecoder extends LengthFieldBasedFrameDecoder
A decoder which deserializes the received ChannelBuffers 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.

  • Field Details

  • Constructor Details

    • ObjectDecoder

      public ObjectDecoder(ClassResolver classResolver)
      Creates a new decoder whose maximum object size is 1048576 bytes. If the size of the received object is greater than 1048576 bytes, a StreamCorruptedException will be raised.
      Parameters:
      classResolver - the ClassResolver to 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, StreamCorruptedException will be raised.
      classResolver - the ClassResolver 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 the FrameDecoder.extractFrame(ChannelBuffer, int, int) method, to make optimizations easier later.
      Overrides:
      decode in class LengthFieldBasedFrameDecoder
      Parameters:
      ctx - the context of this handler
      channel - the current channel
      buffer - 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

      protected ChannelBuffer extractFrame(ChannelBuffer buffer, int index, int length)
      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 class FrameDecoder