|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
T
- The type of objects serialized and interpreted by this Serializer
.public interface Serializer<T>
Serializers are used by DatabaseBackend
:s to
serialize data when writing it to disk, and to interpret serialized data when
reading it again. HeliDB comes with serializers for primitive datatypes and
String
:s. Database-using applications may also provide their own
Serializer
implementations for data types that are not supported by
HeliDB out of the box.
Serializer implementations should not contain any mutable internal state. Object instances are reused many times over and may be used simultaneously by several execution threads.
An implementation decides if it permits null
values and, in that
case, how to serialize them. See isNullValuesPermitted()
.
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. |
Method Detail |
---|
int getSerializedSize()
-1
is
returned.
-1
if the size of the serialized data is variable.boolean isNullValuesPermitted()
null
values?
true
if this serializer permits null
values.T interpret(byte[] barr) throws SerializationException, ArrayIndexOutOfBoundsException
byte
array to an object of the type
handled by the Serializer
implementation.
barr
- The byte
array containing the data.
SerializationException
- If the data in the byte
array
cannot be interpreted.
ArrayIndexOutOfBoundsException
- If the array is to small.interpret(byte[], int, int)
T interpret(byte[] barr, int offset, int length) throws SerializationException, ArrayIndexOutOfBoundsException
byte
array to an object of the type
handled by the Serializer
implementation.
barr
- The byte
array containing the data.offset
- The start position of the data.length
- The length of the data.
SerializationException
- If the data in the byte
array
cannot be interpreted.
ArrayIndexOutOfBoundsException
- If enough data cannot be read from
the array at the supplied position.interpret(byte[])
byte[] serialize(T o) throws NullPointerException, SerializationException
byte
array.
o
- The object to serialize.
byte
array.
NullPointerException
- If o
is null
and the Serializer
implementation does not support null
objects.
SerializationException
- If o
cannot be serialized.int serialize(T o, byte[] barr, int offset) throws NullPointerException, SerializationException, ArrayIndexOutOfBoundsException
byte
array.
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.
NullPointerException
- If o
is null
and the Serializer
implementation does not support null
objects.
SerializationException
- If o
cannot be serialized or if
the data does not fit into barr
.
ArrayIndexOutOfBoundsException
- If the array cannot accommodate
all data.T read(RandomAccess ra, int size) throws WrappedIOException, NotEnoughDataException, SerializationException
RandomAccess
' current position. The
position in the RandomAccess
is incremented by size
bytes.
ra
- The RandomAccess
to read from.size
- The size of the value.
WrappedIOException
- On I/O errors.
NotEnoughDataException
- If there is not enough data left in the
RandomAccess
.
SerializationException
- If the supplied data size is invalid.T read(InputStream is, int size) throws WrappedIOException, NotEnoughDataException, SerializationException
InputStream
.
is
- The InputStream
to read from.size
- The size of the value.
WrappedIOException
- On I/O errors.
NotEnoughDataException
- If there is not enough data left to read
from the InputStream
.
SerializationException
- If the supplied data size is invalid.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |