A
- the type of object that the Serializer handles.public interface Serializer<A>
extends java.util.Comparator<A>
Implementing classes do not have to be thread safe.
Modifier and Type | Field and Description |
---|---|
static GroupSerializer<java.math.BigDecimal> |
BIG_DECIMAL |
static GroupSerializer<java.math.BigInteger> |
BIG_INTEGER |
static GroupSerializer<java.lang.Boolean> |
BOOLEAN
A predefined
Serializer that handles non-null
Booleans whereby Booleans are serialized to a one byte
format. |
static GroupSerializer<java.lang.Byte> |
BYTE
A predefined
Serializer that handles non-null Bytes
whereby Bytes are serialized to a one byte format. |
static GroupSerializer<byte[]> |
BYTE_ARRAY
Serializes
byte[] it adds header which contains size information |
static GroupSerializer<byte[]> |
BYTE_ARRAY_DELTA |
static GroupSerializer<byte[]> |
BYTE_ARRAY_DELTA2 |
static Serializer<byte[]> |
BYTE_ARRAY_NOSIZE
Serializes
byte[] directly into underlying store It does not
store size, so it can not be used in Maps and other collections. |
static GroupSerializer<java.lang.Character> |
CHAR
A predefined
Serializer that handles non-null
Characters . |
static GroupSerializer<char[]> |
CHAR_ARRAY
Serializes
char[] it adds header which contains size information |
static GroupSerializer<java.lang.Class<?>> |
CLASS |
static GroupSerializer<java.util.Date> |
DATE |
static GroupSerializer<java.lang.Double> |
DOUBLE
A predefined
Serializer that handles non-null
Doubles whereby Doubles are serialized to an 8 byte
format. |
static GroupSerializer<double[]> |
DOUBLE_ARRAY
Serializes
double[] it adds header which contains size
information |
static GroupSerializer |
ELSA |
static GroupSerializer<java.lang.Float> |
FLOAT
A predefined
Serializer that handles non-null
Floats whereby Floats are serialized to a 4 byte format. |
static GroupSerializer<float[]> |
FLOAT_ARRAY |
static GroupSerializer<java.lang.Object> |
ILLEGAL_ACCESS
A predefined
Serializer that always throws an
IllegalAccessError when invoked. |
static GroupSerializer<int[]> |
INT_ARRAY
Serializes
int[] it adds header which contains size information |
static GroupSerializer<java.lang.Integer> |
INTEGER
A predefined
Serializer that handles non-null
Integers whereby Integers are serialized to a 4 byte
format. |
static GroupSerializer<java.lang.Integer> |
INTEGER_DELTA
A predefined
Serializer that handles non-null
Integers whereby Integers are serialized to a compressed
byte format and neighboring Integers are delta encoded in BTreeMaps. |
static GroupSerializer<java.lang.Integer> |
INTEGER_PACKED
A predefined
Serializer that handles non-null
Integers whereby Integers are serialized to a compressed
byte format.The Serializer also stores the Longs's size, allowing it to
be used as a GroupSerializer in BTreeMaps. |
static GroupSerializer |
JAVA
A predefined
Serializer that handles non-null
Serializable Java objects whereby the standard Java serialization
will be applied using ObjectInputStream and
ObjectOutputStream methods. |
static GroupSerializer<java.lang.Long> |
LONG
A predefined
Serializer that handles non-null Longs
whereby Longs are serialized to an 8 byte format. |
static GroupSerializer<long[]> |
LONG_ARRAY
Serializes
long[] it adds header which contains size information |
static GroupSerializer<java.lang.Long> |
LONG_DELTA
A predefined
Serializer that handles non-null Longs
whereby Longs are serialized to a compressed byte format and neighboring
Longs are delta encoded in BTreeMaps. |
static GroupSerializer<java.lang.Long> |
LONG_PACKED
A predefined
Serializer that handles non-null Longs
whereby Longs are serialized to a compressed byte format. |
static GroupSerializer<java.lang.Long> |
RECID
A predefined
Serializer that handles non-null Longs
used as a recid whereby recids are serialized to an eight byte format
including a checksum. |
static GroupSerializer<long[]> |
RECID_ARRAY
A predefined
Serializer that handles non-null arrays of longs
used as a recids whereby recids are serialized to an eight byte format
including a checksum. |
static GroupSerializer<java.lang.Short> |
SHORT
A predefined
Serializer that handles non-null
Shorts whereby Shorts are serialized to a 2 byte format. |
static GroupSerializer<short[]> |
SHORT_ARRAY |
static GroupSerializer<java.lang.String> |
STRING
A predefined
Serializer that handles non-null
Strings whereby Strings are serialized to a UTF-8 encoded
format. |
static GroupSerializer<java.lang.String> |
STRING_ASCII
A predefined
Serializer that handles non-null
Strings whereby Strings are serialized to a ASCII encoded
format (8 bit character) which is faster than using a UTF-8 format. |
static GroupSerializer<java.lang.String> |
STRING_DELTA
A predefined
Serializer that handles non-null
Strings whereby Strings are serialized to a UTF-8 encoded
format. |
static GroupSerializer<java.lang.String> |
STRING_DELTA2
A predefined
Serializer that handles non-null
Strings whereby Strings are serialized to a UTF-8 encoded
format. |
static GroupSerializer<java.lang.String> |
STRING_INTERN
A predefined
Serializer that handles non-null
Strings whereby Strings are serialized to a UTF-8 encoded
format. |
static Serializer<java.lang.String> |
STRING_NOSIZE
A predefined
Serializer that handles non-null
Strings whereby Strings are serialized to a UTF-8 encoded
format. |
static GroupSerializer<java.lang.String> |
STRING_ORIGHASH
A predefined
Serializer that handles non-null
Strings whereby Strings are serialized to a UTF-8 encoded
format. |
static GroupSerializer<java.util.UUID> |
UUID
Serializers
UUID class |
Modifier and Type | Method and Description |
---|---|
default A |
clone(A value)
Creates binary copy of given object.
|
default int |
compare(A first,
A second) |
A |
deserialize(DataInput2 input,
int available)
Deserializes and returns the content of the given
DataInput2 . |
default A |
deserializeFromLong(long input,
int available)
Deserializes and returns the content of the given long.
|
default boolean |
equals(A first,
A second)
Returns if the first and second arguments are equal to each other.
|
default int |
fixedSize()
Returns the fixed size of the serialized form in bytes or -1 if the size
is not fixed (e.g.
|
default int |
hashCode(A o,
int seed)
Returns a hash code of a given non-null argument.
|
default boolean |
isTrusted()
Returns if this Serializer is trusted to always read the same number of
bytes as it writes for any given object being serialized/de-serialized.
|
default boolean |
needsAvailableSizeHint()
TODO: Document this method
|
void |
serialize(DataOutput2 out,
A value)
Serializes the content of the given value into the given
DataOutput2 . |
static final GroupSerializer<java.lang.Character> CHAR
Serializer
that handles non-null
Characters
.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<java.lang.String> STRING_ORIGHASH
Serializer
that handles non-null
Strings
whereby Strings are serialized to a UTF-8 encoded
format. The Serializer also stores the String's size, allowing it to be
used as a GroupSerializer in BTreeMaps.
This Serializer hashes Strings using the original hash code method as
opposed to the STRING
Serializer.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
STRING
static final GroupSerializer<java.lang.String> STRING
Serializer
that handles non-null
Strings
whereby Strings are serialized to a UTF-8 encoded
format. The Serializer also stores the String's size, allowing it to be
used as a GroupSerializer in BTreeMaps.
This Serializer hashes Strings using a specially tailored hash code
method as opposed to the STRING_ORIGHASH
Serializer.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
STRING_ORIGHASH
static final GroupSerializer<java.lang.String> STRING_DELTA
Serializer
that handles non-null
Strings
whereby Strings are serialized to a UTF-8 encoded
format. The Serializer also stores the String's size, allowing it to be
used as a GroupSerializer in BTreeMaps. Neighboring strings may be delta
encoded for increased storage efficency.
This Serializer hashes Strings using a specially tailored hash code
method as opposed to the STRING_ORIGHASH
Serializer.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
STRING
static final GroupSerializer<java.lang.String> STRING_DELTA2
Serializer
that handles non-null
Strings
whereby Strings are serialized to a UTF-8 encoded
format. The Serializer also stores the String's size, allowing it to be
used as a GroupSerializer in BTreeMaps. Neighboring strings may be delta
encoded for increased storage efficency.
This Serializer hashes Strings using a specially tailored hash code
method as opposed to the STRING_ORIGHASH
Serializer.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
STRING
static final GroupSerializer<java.lang.String> STRING_INTERN
Serializer
that handles non-null
Strings
whereby Strings are serialized to a UTF-8 encoded
format. The Serializer also stores the String's size, allowing it to be
used as a GroupSerializer in BTreeMaps. Neighboring strings may be delta
encoded for increased storage efficency.
Deserialized strings are automatically interned String.intern()
allowing a more heap space efficient storage for repeated strings.
This Serializer hashes Strings using a specially tailored hash code
method as opposed to the STRING_ORIGHASH
Serializer.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
STRING
static final GroupSerializer<java.lang.String> STRING_ASCII
Serializer
that handles non-null
Strings
whereby Strings are serialized to a ASCII encoded
format (8 bit character) which is faster than using a UTF-8 format. The
Serializer also stores the String's size, allowing it to be used as a
GroupSerializer in BTreeMaps.
This Serializer hashes Strings using a specially tailored hash code
method as opposed to the STRING_ORIGHASH
Serializer.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
STRING_ORIGHASH
static final Serializer<java.lang.String> STRING_NOSIZE
Serializer
that handles non-null
Strings
whereby Strings are serialized to a UTF-8 encoded
format. The Serializer does not store the String's size, thereby
preventing it from being used as a GroupSerializer.
This Serializer hashes Strings using the original hash code method as
opposed to the STRING
Serializer.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
STRING_ORIGHASH
static final GroupSerializer<java.lang.Long> LONG
Serializer
that handles non-null Longs
whereby Longs are serialized to an 8 byte format. The Serializer also
stores the Longs's size, allowing it to be used as a GroupSerializer in
BTreeMaps.
This Serializer hashes Longs using the original Long.hashCode()
method.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<java.lang.Long> LONG_PACKED
Serializer
that handles non-null Longs
whereby Longs are serialized to a compressed byte format. The Serializer
also stores the Longs's size, allowing it to be used as a GroupSerializer
in BTreeMaps.
Smaller positive values occupy less than 8 bytes. Large and negative values could occupy 8 or 9 bytes.
This Serializer hashes Longs using the original Long.hashCode()
method.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<java.lang.Long> LONG_DELTA
Serializer
that handles non-null Longs
whereby Longs are serialized to a compressed byte format and neighboring
Longs are delta encoded in BTreeMaps. Neighbors with a small delta can be
encoded using a single byte.
Smaller positive values occupy less than 8 bytes. Large and negative values could occupy 8 or 9 bytes.
This Serializer hashes Longs using the original Long.hashCode()
method.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<java.lang.Integer> INTEGER
Serializer
that handles non-null
Integers
whereby Integers are serialized to a 4 byte
format.
This Serializer hashes Integers using the original
Integer.hashCode()
method.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<java.lang.Integer> INTEGER_PACKED
Serializer
that handles non-null
Integers
whereby Integers are serialized to a compressed
byte format.The Serializer also stores the Longs's size, allowing it to
be used as a GroupSerializer in BTreeMaps.
Smaller positive values occupy less than 4 bytes. Large and negative values could occupy 4 or 5 bytes.
This Serializer hashes Integers using the original
Integer.hashCode()
method.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<java.lang.Integer> INTEGER_DELTA
Serializer
that handles non-null
Integers
whereby Integers are serialized to a compressed
byte format and neighboring Integers are delta encoded in BTreeMaps.
Neighbors with a small delta can be encoded using a single byte.
Smaller positive values occupy less than 4 bytes. Large and negative values could occupy 4 or 5 bytes.
This Serializer hashes Integers using the original
Integer.hashCode()
method.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<java.lang.Boolean> BOOLEAN
Serializer
that handles non-null
Booleans
whereby Booleans are serialized to a one byte
format.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<java.lang.Long> RECID
Serializer
that handles non-null Longs
used as a recid whereby recids are serialized to an eight byte format
including a checksum.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<long[]> RECID_ARRAY
Serializer
that handles non-null arrays of longs
used as a recids whereby recids are serialized to an eight byte format
including a checksum.
If a null
array is passed to the Serializer, a
NullPointerException
will be thrown.
If an array that contains a null
value is passed to the
Serializer, a NullPointerException
will be thrown.
static final GroupSerializer<java.lang.Object> ILLEGAL_ACCESS
Serializer
that always throws an
IllegalAccessError
when invoked.
This serializer can be used for testing and assertions.
static final GroupSerializer<byte[]> BYTE_ARRAY
byte[]
it adds header which contains size informationstatic final GroupSerializer<byte[]> BYTE_ARRAY_DELTA
static final GroupSerializer<byte[]> BYTE_ARRAY_DELTA2
static final Serializer<byte[]> BYTE_ARRAY_NOSIZE
byte[]
directly into underlying store It does not
store size, so it can not be used in Maps and other collections.static final GroupSerializer<char[]> CHAR_ARRAY
char[]
it adds header which contains size informationstatic final GroupSerializer<int[]> INT_ARRAY
int[]
it adds header which contains size informationstatic final GroupSerializer<long[]> LONG_ARRAY
long[]
it adds header which contains size informationstatic final GroupSerializer<double[]> DOUBLE_ARRAY
double[]
it adds header which contains size
informationstatic final GroupSerializer JAVA
Serializer
that handles non-null
Serializable
Java objects whereby the standard Java serialization
will be applied using ObjectInputStream
and
ObjectOutputStream
methods.
This Serializer hashes Objects using a specially tailored hash code
method that, in turn, is using the objects own hashCode()
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
Serializable
static final GroupSerializer ELSA
static final GroupSerializer<java.util.UUID> UUID
UUID
classstatic final GroupSerializer<java.lang.Byte> BYTE
Serializer
that handles non-null Bytes
whereby Bytes are serialized to a one byte format.
This Serializer hashes Bytes using the original Byte.hashCode()
method.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<java.lang.Float> FLOAT
Serializer
that handles non-null
Floats
whereby Floats are serialized to a 4 byte format.
The Serializer also stores the Float's size, allowing it to be used as a
GroupSerializer in BTreeMaps.
This Serializer hashes Floats using the original Float.hashCode()
method.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<java.lang.Double> DOUBLE
Serializer
that handles non-null
Doubles
whereby Doubles are serialized to an 8 byte
format. The Serializer also stores the Float's size, allowing it to be
used as a GroupSerializer in BTreeMaps.
This Serializer hashes Doubles using the original
Double.hashCode()
method.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<java.lang.Short> SHORT
Serializer
that handles non-null
Shorts
whereby Shorts are serialized to a 2 byte format.
The Serializer also stores the Short's size, allowing it to be used as a
GroupSerializer in BTreeMaps.
This Serializer hashes Shorts using the original Short.hashCode()
method.
If a null
value is passed to the Serializer, a
NullPointerException
will be thrown.
static final GroupSerializer<short[]> SHORT_ARRAY
static final GroupSerializer<float[]> FLOAT_ARRAY
static final GroupSerializer<java.math.BigInteger> BIG_INTEGER
static final GroupSerializer<java.math.BigDecimal> BIG_DECIMAL
static final GroupSerializer<java.lang.Class<?>> CLASS
static final GroupSerializer<java.util.Date> DATE
void serialize(@NotNull DataOutput2 out, @NotNull A value) throws java.io.IOException
DataOutput2
.out
- DataOutput2 to save object intovalue
- Object to serializejava.io.IOException
- in case of an I/O errorA deserialize(@NotNull DataInput2 input, int available) throws java.io.IOException
DataInput2
.input
- DataInput2 to de-serialize data fromavailable
- how many bytes that are available in the DataInput2 for
reading, may be -1 (in streams) or 0 (null).DataInput2
java.io.IOException
- in case of an I/O errordefault int fixedSize()
Some optimizations can be applied to serializers with a fixed size.
default boolean isTrusted()
MapDB has a relaxed record size boundary checking. It expects deserializers to read exactly as many bytes as were written during serialization. If a deserializer reads more bytes than it wrote, it might start reading others record data in store.
Some serializers (Kryo) have problems with this. To prevent this, we can
not read data directly from a store, but we must copy them into separate
byte[]
buffers. Thus, zero-copy optimizations are disabled by
default, but can be explicitly enabled here by letting this method return
true
.
This flag indicates if this serializer was 'verified' to read as many bytes as it writes. It should also be much better tested etc.
default int compare(A first, A second)
compare
in interface java.util.Comparator<A>
default boolean equals(A first, A second)
null
, true
is
returned and if exactly one argument is null
, false
is
returned.first
- an objectsecond
- another object to be compared with the first object for
equalityObject.equals(Object)
default int hashCode(@NotNull A o, int seed)
o
- an objectseed
- used to "scramble" thejava.lang.NullPointerException
- if the provided object is nullObject.hashCode()
default boolean needsAvailableSizeHint()
default A deserializeFromLong(long input, int available) throws java.io.IOException
input
- long to de-serialize data fromavailable
- how many bytes that are available in the long for
reading, or 0 (null).java.io.IOException
- in case of an I/O errorCopyright © 2018. All Rights Reserved.