org.ehcache.internal.serialization
Class CompactJavaSerializer<T>
java.lang.Object
org.ehcache.internal.serialization.CompactJavaSerializer<T>
- All Implemented Interfaces:
- java.io.Closeable, Serializer<T>
public class CompactJavaSerializer<T>
- extends java.lang.Object
- implements Serializer<T>
A trivially compressed Java serialization based serializer.
Class descriptors in the resultant bytes are encoded as integers. Mappings
between the integer representation and the ObjectStreamClass
, and the
Class
and the integer representation are stored in a single on-heap
map.
Method Summary |
void |
close()
|
protected static java.io.ObjectStreamClass |
disconnect(java.io.ObjectStreamClass desc)
|
boolean |
equals(T object,
java.nio.ByteBuffer binary)
Checks if the given instance and serial form are representations of the same instance. |
java.io.ObjectInputStream |
getObjectInputStream(java.io.InputStream input)
|
java.io.ObjectOutputStream |
getObjectOutputStream(java.io.OutputStream out)
|
protected int |
getOrAddMapping(java.io.ObjectStreamClass desc)
|
protected java.util.Map<java.lang.Integer,java.io.ObjectStreamClass> |
getSerializationMappings()
|
T |
read(java.nio.ByteBuffer binary)
Reconstructs an instance from the given serial form. |
java.nio.ByteBuffer |
serialize(T object)
Transforms the given instance into its serial form. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CompactJavaSerializer
public CompactJavaSerializer(java.lang.ClassLoader loader)
CompactJavaSerializer
protected CompactJavaSerializer(java.lang.ClassLoader loader,
java.util.Map<java.lang.Integer,java.io.ObjectStreamClass> mappings)
getSerializationMappings
protected java.util.Map<java.lang.Integer,java.io.ObjectStreamClass> getSerializationMappings()
serialize
public java.nio.ByteBuffer serialize(T object)
throws SerializerException
- Description copied from interface:
Serializer
- Transforms the given instance into its serial form.
- Specified by:
serialize
in interface Serializer<T>
- Parameters:
object
- the instance to serialize
- Returns:
- the binary representation of the serial form
- Throws:
SerializerException
- if serialization fails
read
public T read(java.nio.ByteBuffer binary)
throws java.lang.ClassNotFoundException,
SerializerException
- Description copied from interface:
Serializer
- Reconstructs an instance from the given serial form.
- Specified by:
read
in interface Serializer<T>
- Parameters:
binary
- the binary representation of the serial form
- Returns:
- the de-serialized instance
- Throws:
java.lang.ClassNotFoundException
- if the type to de-serialize to cannot be found
SerializerException
- if reading the byte buffer fails
getObjectOutputStream
public java.io.ObjectOutputStream getObjectOutputStream(java.io.OutputStream out)
throws java.io.IOException
- Throws:
java.io.IOException
getObjectInputStream
public java.io.ObjectInputStream getObjectInputStream(java.io.InputStream input)
throws java.io.IOException
- Throws:
java.io.IOException
equals
public boolean equals(T object,
java.nio.ByteBuffer binary)
throws java.lang.ClassNotFoundException,
SerializerException
- Description copied from interface:
Serializer
- Checks if the given instance and serial form are representations of the same instance.
- Specified by:
equals
in interface Serializer<T>
- Parameters:
object
- the instance to checkbinary
- the serial form to check
- Returns:
true
if both parameters represent the same instance, false
otherwise
- Throws:
java.lang.ClassNotFoundException
- if the type to de-serialize to cannot be found
SerializerException
- if reading the byte buffer fails
getOrAddMapping
protected int getOrAddMapping(java.io.ObjectStreamClass desc)
throws java.io.IOException
- Throws:
java.io.IOException
close
public void close()
- Specified by:
close
in interface java.io.Closeable
disconnect
protected static java.io.ObjectStreamClass disconnect(java.io.ObjectStreamClass desc)