Class ObjectEncoder

  • All Implemented Interfaces:,

    public class ObjectEncoder
    An encoder which serializes a Java object into a message.

    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.

    $Rev:231 $, $Date:2008-06-12 16:44:50 +0900 (목, 12 6월 2008) $
    The Netty Project (, Trustin Lee (
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ObjectEncoder.FailedWriteException  
      • Nested classes/interfaces inherited from interface
    • Constructor Summary

      Constructor Description
      Creates a new encoder with the estimated length of 512 bytes.
      ObjectEncoder​(int estimatedLength, boolean preferDirect)
      Creates a new encoder.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected io.netty.buffer.ByteBuf allocateBuffer​( ctx, int estimatedSize, boolean preferDirect)  
      void write​( ctx, Object msg, promise)  
      • Methods inherited from class

        bind, close, connect, deregister, disconnect, flush, read
      • Methods inherited from class

        ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharable
      • Methods inherited from interface

        exceptionCaught, handlerAdded, handlerRemoved
    • Constructor Detail

      • ObjectEncoder

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

        public ObjectEncoder​(int estimatedLength,
                             boolean preferDirect)
        Creates a new encoder.
        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 Detail

      • write

        public void write​( ctx,
                          Object msg,
                   throws Exception
        Specified by:
        write in interface
        write in class
      • allocateBuffer

        protected io.netty.buffer.ByteBuf allocateBuffer​( ctx,
                                                         int estimatedSize,
                                                         boolean preferDirect)
                                                  throws Exception