org.jboss.netty.handler.codec.serialization
Class ObjectDecoder

java.lang.Object
  extended by org.jboss.netty.channel.SimpleChannelUpstreamHandler
      extended by org.jboss.netty.handler.codec.frame.FrameDecoder
          extended by org.jboss.netty.handler.codec.serialization.ObjectDecoder
All Implemented Interfaces:
ChannelHandler, ChannelUpstreamHandler

public class ObjectDecoder
extends FrameDecoder

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.

Version:
$Rev: 1685 $, $Date: 2009-08-28 16:15:49 +0900 (금, 28 8 2009) $
Author:
The Netty Project (netty-dev@lists.jboss.org), Trustin Lee (tlee@redhat.com)

Constructor Summary
ObjectDecoder()
          Creates a new decoder whose maximum object size is 1048576 bytes.
ObjectDecoder(int maxObjectSize)
          Creates a new decoder with the specified maximum object size.
ObjectDecoder(int maxObjectSize, ClassLoader classLoader)
          Creates a new decoder with the specified maximum object size.
 
Method Summary
protected  Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer)
          Decodes the received packets so far into a frame.
 
Methods inherited from class org.jboss.netty.handler.codec.frame.FrameDecoder
channelClosed, channelDisconnected, decodeLast, exceptionCaught, messageReceived
 
Methods inherited from class org.jboss.netty.channel.SimpleChannelUpstreamHandler
channelBound, channelConnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, handleUpstream, writeComplete
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectDecoder

public ObjectDecoder()
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.


ObjectDecoder

public ObjectDecoder(int maxObjectSize)
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.

ObjectDecoder

public ObjectDecoder(int maxObjectSize,
                     ClassLoader classLoader)
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.
classLoader - the ClassLoader which will load the class of the serialized object
Method Detail

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.

Specified by:
decode in class FrameDecoder
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


Copyright © 2008-2009 JBoss, by Red Hat. All Rights Reserved.