- All Known Implementing Classes:
BooleanSerializer
,BufferedSerializer
,ByteArraySerializer
,ByteSerializer
,CharacterSerializer
,CharArraySerializer
,DoubleSerializer
,FloatSerializer
,GZIPSerializer
,IntegerSerializer
,LongSerializer
,ObjectSerializer
,ShortSerializer
public interface Serializer<E>
Writes and reads serialized forms of objects to and from
OutputStream
and InputStream
.
There is no need to handle null
values as they will not be passed-in.
All Serializers
should be considered not thread-safe.- Author:
- AO Industries, Inc.
-
Method Summary
Modifier and TypeMethodDescriptionRestores an object from anInputStream
.long
getSerializedSize
(E value) Determines the size of the object after serialization.boolean
If a serializer always creates the same number of bytes, containers can choose a fixed-size block for higher performance.void
serialize
(E value, OutputStream out) Writes the object to theOutputStream
.
-
Method Details
-
isFixedSerializedSize
boolean isFixedSerializedSize()If a serializer always creates the same number of bytes, containers can choose a fixed-size block for higher performance. If this method returnstrue
,getSerializedSize(java.lang.Object)
must return the same value for every access, it may be accessed with anull
parameter, and it may be accessed less than once per serialized object.- 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
Determines the size of the object after serialization. This allows some optimizations avoiding unnecessary copying of data.
The common pattern is:- Get size from
getSerializedSize(java.lang.Object)
- Allocate appropriate space
- Write serialized object with
serialize(java.lang.Object, java.io.OutputStream)
getSerializedSize(java.lang.Object)
andserialize(java.lang.Object, java.io.OutputStream)
when it can reduce processing time.- Returns:
- the exact number of bytes the object will take to serialize
- Throws:
IOException
- Get size from
-
serialize
Writes the object to theOutputStream
.null
will not be passed in.- Throws:
IOException
-
deserialize
Restores an object from anInputStream
.- Throws:
IOException
-