java.lang.Object
com.aoapps.persistence.BufferedSerializer<E>
- All Implemented Interfaces:
Serializer<E>
- Direct Known Subclasses:
ObjectSerializer
Serializes any objects by using a buffer between the
Serializer.getSerializedSize(java.lang.Object) and
Serializer.serialize(java.lang.Object, java.io.OutputStream) 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.
- Author:
- AO Industries, Inc.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal longgetSerializedSize(E value) Determines the size of the object after serialization.final booleanIf a serializer always creates the same number of bytes, containers can choose a fixed-size block for higher performance.protected abstract voidserialize(E value, ByteArrayOutputStream buffer) final voidserialize(E value, OutputStream out) Writes the object to theOutputStream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.aoapps.persistence.Serializer
deserialize
-
Constructor Details
-
BufferedSerializer
protected BufferedSerializer()
-
-
Method Details
-
isFixedSerializedSize
public final boolean isFixedSerializedSize()Description copied from interface:SerializerIf a serializer always creates the same number of bytes, containers can choose a fixed-size block for higher performance. If this method returnstrue,Serializer.getSerializedSize(java.lang.Object)must return the same value for every access, it may be accessed with anullparameter, and it may be accessed less than once per serialized object.- Specified by:
isFixedSerializedSizein interfaceSerializer<E>- Returns:
- To indicate that the same number of bytes will be created, return
true. Otherwise, there may be a dynamic number of bytes and returnfalse.
-
getSerializedSize
Description copied from interface:SerializerDetermines the size of the object after serialization. This allows some optimizations avoiding unnecessary copying of data.The common pattern is:
- Get size from
Serializer.getSerializedSize(java.lang.Object) - Allocate appropriate space
- Write serialized object with
Serializer.serialize(java.lang.Object, java.io.OutputStream)
It may be best to remember the most recently used object between calls to
Serializer.getSerializedSize(java.lang.Object)andSerializer.serialize(java.lang.Object, java.io.OutputStream)when it can reduce processing time.- Specified by:
getSerializedSizein interfaceSerializer<E>- Returns:
- the exact number of bytes the object will take to serialize
- Throws:
IOException
- Get size from
-
serialize
Description copied from interface:SerializerWrites the object to theOutputStream.nullwill not be passed in.- Specified by:
serializein interfaceSerializer<E>- Throws:
IOException
-
serialize
- Throws:
IOException
-
