Class BufferedSerializer<E>

  • All Implemented Interfaces:
    Direct Known Subclasses:

    public abstract class BufferedSerializer<E>
    extends Object
    implements Serializer<E>
    Serializes any objects by using a buffer between the getSerializedSize and serialize calls. This avoids serializing the object twice in the common sequence of getSerializedSize followed by serialize. This and all subclasses are not fixed size. This class is not thread safe.
    AO Industries, Inc.
    • Constructor Detail

      • BufferedSerializer

        public BufferedSerializer()
    • Method Detail

      • isFixedSerializedSize

        public final boolean isFixedSerializedSize()
        Description copied from interface: Serializer
        If a serializer always creates the same number of bytes, containers can choose a fixed-size block for higher performance. If this method returns true, getSerializedSize must return the same value for every access, it may be accessed with a null parameter, and it may be accessed less than once per serialized object.
        Specified by:
        isFixedSerializedSize in interface Serializer<E>
        To indicate that the same number of bytes will be created, return true. Otherwise, there may be a dynamic number of bytes and return false.
      • getSerializedSize

        public final long getSerializedSize​(E value)
                                     throws IOException
        Description copied from interface: Serializer

        Determines the size of the object after serialization. This allows some optimizations avoiding unnecessary copying of data.

        The common pattern is:
        1. Get size from getSerializedSize
        2. Allocate appropriate space
        3. Write serialized object with serialize
        It may be best to remember the most recently used object between calls to getSerializedSize and serialize when it can reduce processing time.
        Specified by:
        getSerializedSize in interface Serializer<E>
        the exact number of bytes the object will take to serialize