- java.lang.Object
-
- com.aoapps.persistence.IntegerSerializer
-
- All Implemented Interfaces:
Serializer<Integer>
public class IntegerSerializer extends Object implements Serializer<Integer>
SerializesInteger
objects. This class is not thread safe.- Author:
- AO Industries, Inc.
-
-
Constructor Summary
Constructors Constructor Description IntegerSerializer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Integer
deserialize(InputStream in)
Restores an object from anInputStream
.long
getSerializedSize(Integer 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.void
serialize(Integer value, OutputStream out)
Writes the object to theOutputStream
.
-
-
-
Method Detail
-
isFixedSerializedSize
public 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 returnstrue
,Serializer.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.- Specified by:
isFixedSerializedSize
in interfaceSerializer<Integer>
- 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
public long getSerializedSize(Integer value)
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:- Get size from
Serializer.getSerializedSize(java.lang.Object)
- Allocate appropriate space
- Write serialized object with
Serializer.serialize(java.lang.Object, java.io.OutputStream)
Serializer.getSerializedSize(java.lang.Object)
andSerializer.serialize(java.lang.Object, java.io.OutputStream)
when it can reduce processing time.- Specified by:
getSerializedSize
in interfaceSerializer<Integer>
- Returns:
- the exact number of bytes the object will take to serialize
- Get size from
-
serialize
public void serialize(Integer value, OutputStream out) throws IOException
Description copied from interface:Serializer
Writes the object to theOutputStream
.null
will not be passed in.- Specified by:
serialize
in interfaceSerializer<Integer>
- Throws:
IOException
-
deserialize
public Integer deserialize(InputStream in) throws IOException
Description copied from interface:Serializer
Restores an object from anInputStream
.- Specified by:
deserialize
in interfaceSerializer<Integer>
- Throws:
IOException
-
-