org.helidb.lang.serializer
Class SerializableSerializer<T extends Serializable>

java.lang.Object
  extended by org.helidb.lang.serializer.SerializableSerializer<T>
All Implemented Interfaces:
Serializer<T>

public class SerializableSerializer<T extends Serializable>
extends Object
implements Serializer<T>

This is a Serializer for generic Serializable objects.

Often, using a custom serializer for the serialized class is preferable since that gives greater control over how data is stored.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
helidb-core

Constructor Summary
SerializableSerializer()
           
 
Method Summary
 int getSerializedSize()
          If the serialized data produced by this serializer always is of the same size, return that size (in number of bytes).
 T interpret(byte[] barr)
          Interpret the data in the byte array to an object of the type handled by the Serializer implementation.
 T interpret(byte[] barr, int offset, int length)
          Interpret the data in the byte array to an object of the type handled by the Serializer implementation.
 boolean isNullValuesPermitted()
          Does this serializer permit null values?
 T read(InputStream is, int size)
          Read a value from the InputStream.
 T read(RandomAccess ra, int size)
          Read a value from the RandomAccess' current position.
 byte[] serialize(T o)
          Serialize the supplied object into a new byte array.
 int serialize(T o, byte[] barr, int offset)
          Serialize the supplied object into the byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerializableSerializer

public SerializableSerializer()
Method Detail

getSerializedSize

public int getSerializedSize()
Description copied from interface: Serializer
If the serialized data produced by this serializer always is of the same size, return that size (in number of bytes). Otherwise -1 is returned.

Specified by:
getSerializedSize in interface Serializer<T extends Serializable>
Returns:
-1 (variable size).

isNullValuesPermitted

public boolean isNullValuesPermitted()
Description copied from interface: Serializer
Does this serializer permit null values?

Specified by:
isNullValuesPermitted in interface Serializer<T extends Serializable>
Returns:
false.

interpret

public T interpret(byte[] barr)
Description copied from interface: Serializer
Interpret the data in the byte array to an object of the type handled by the Serializer implementation.

Specified by:
interpret in interface Serializer<T extends Serializable>
Parameters:
barr - The byte array containing the data.
Returns:
The interpreted object.
See Also:
Serializer.interpret(byte[], int, int)

interpret

public T interpret(byte[] barr,
                   int offset,
                   int length)
Description copied from interface: Serializer
Interpret the data in the byte array to an object of the type handled by the Serializer implementation.

Specified by:
interpret in interface Serializer<T extends Serializable>
Parameters:
barr - The byte array containing the data.
offset - The start position of the data.
length - The length of the data.
Returns:
The interpreted object.
See Also:
Serializer.interpret(byte[])

serialize

public byte[] serialize(T o)
Description copied from interface: Serializer
Serialize the supplied object into a new byte array.

Specified by:
serialize in interface Serializer<T extends Serializable>
Parameters:
o - The object to serialize.
Returns:
The object serialized into a byte array.

serialize

public int serialize(T o,
                     byte[] barr,
                     int offset)
Description copied from interface: Serializer
Serialize the supplied object into the byte array.

Specified by:
serialize in interface Serializer<T extends Serializable>
Parameters:
o - The object to serialize.
barr - The byte array to serialize it to.
offset - The start position to write data at in the byte array.
Returns:
The number of bytes written to the array.

read

public T read(RandomAccess ra,
              int size)
Description copied from interface: Serializer
Read a value from the RandomAccess' current position. The position in the RandomAccess is incremented by size bytes.

Specified by:
read in interface Serializer<T extends Serializable>
Parameters:
ra - The RandomAccess to read from.
size - The size of the value.
Returns:
The value.

read

public T read(InputStream is,
              int size)
Description copied from interface: Serializer
Read a value from the InputStream.

Specified by:
read in interface Serializer<T extends Serializable>
Parameters:
is - The InputStream to read from.
size - The size of the value.
Returns:
The value.