Class ObjectEncoder

java.lang.Object
org.jboss.netty.handler.codec.oneone.OneToOneEncoder
org.jboss.netty.handler.codec.serialization.ObjectEncoder
All Implemented Interfaces:
ChannelDownstreamHandler, ChannelHandler

@Sharable public class ObjectEncoder extends OneToOneEncoder
An encoder which serializes a Java object into a ChannelBuffer.

Please note that the serialized form this encoder produces is not compatible with the standard ObjectInputStream. Please use ObjectDecoder or ObjectDecoderInputStream to ensure the interoperability with this encoder.

  • Field Details

    • LENGTH_PLACEHOLDER

      private static final byte[] LENGTH_PLACEHOLDER
    • estimatedLength

      private final int estimatedLength
  • Constructor Details

    • ObjectEncoder

      public ObjectEncoder()
      Creates a new encoder with the estimated length of 512 bytes.
    • ObjectEncoder

      public ObjectEncoder(int estimatedLength)
      Creates a new encoder.
      Parameters:
      estimatedLength - the estimated byte length of the serialized form of an object. If the length of the serialized form exceeds this value, the internal buffer will be expanded automatically at the cost of memory bandwidth. If this value is too big, it will also waste memory bandwidth. To avoid unnecessary memory copy or allocation cost, please specify the properly estimated value.
  • Method Details