Reusable Java library of general tools with minimal external dependencies.
For questions or support, please contact us:
Email: support@aoindustries.com
Phone: 1-800-519-9541
Phone: +1-251-607-9556
Web: https://www.aoindustries.com/contact
public abstract class BufferedSerializer<E> extends Object implements Serializer<E>
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.| Constructor and Description |
|---|
BufferedSerializer() |
| Modifier and Type | Method and Description |
|---|---|
long |
getSerializedSize(E value)
Determines the size of the object after serialization.
|
boolean |
isFixedSerializedSize()
If a serializer always creates the same number of bytes, containers can
choose a fixed-size block for higher performance.
|
protected abstract void |
serialize(E value,
ByteArrayOutputStream buffer) |
void |
serialize(E value,
OutputStream out)
Writes the object to the
OutputStream. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdeserializepublic final boolean isFixedSerializedSize()
Serializertrue, 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.isFixedSerializedSize in interface Serializer<E>true. Otherwise, there may be a dynamic number of
bytes and return false.public final long getSerializedSize(E value) throws IOException
SerializerDetermines the size of the object after serialization. This allows some optimizations avoiding unnecessary copying of data.
The common pattern is:getSerializedSizeserializegetSerializedSize and serialize when it can
reduce processing time.getSerializedSize in interface Serializer<E>IOExceptionpublic final void serialize(E value, OutputStream out) throws IOException
SerializerOutputStream. null will
not be passed in.serialize in interface Serializer<E>IOExceptionprotected abstract void serialize(E value, ByteArrayOutputStream buffer) throws IOException
IOExceptionCopyright © 2000–2016 AO Industries, Inc.. All rights reserved.