Class Serializer<A>
- java.lang.Object
-
- org.mapdb.Serializer<A>
-
- Direct Known Subclasses:
- Serializer.Array, Serializer.CompressionDeflateWrapper, Serializer.CompressionWrapper, SerializerBase
public abstract class Serializer<A> extends java.lang.ObjectProvides serialization and deserialization
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classSerializer.Array<T>static classSerializer.CompressionDeflateWrapper<E>wraps another serializer and (de)compresses its output/input using Deflatestatic classSerializer.CompressionWrapper<E>wraps another serializer and (de)compresses its output/input
-
Field Summary
Fields Modifier and Type Field and Description static Serializer<java.lang.Object>BASICBasic serializer for most classes injava.langandjava.utilpackages.static Serializer<java.math.BigDecimal>BIG_DECIMALstatic Serializer<java.math.BigInteger>BIG_INTEGERstatic Serializer<java.lang.Boolean>BOOLEANstatic Serializer<boolean[]>BOOLEAN_ARRAYstatic Serializer<java.lang.Byte>BYTEstatic Serializer<byte[]>BYTE_ARRAYSerializesbyte[]it adds header which contains size informationstatic Serializer<byte[]>BYTE_ARRAY_NOSIZESerializesbyte[]directly into underlying store It does not store size, so it can not be used in Maps and other collections.static Serializer<java.lang.Character>CHARstatic Serializer<char[]>CHAR_ARRAYSerializeschar[]it adds header which contains size informationstatic Serializer<java.lang.Class<?>>CLASSstatic Serializer<java.util.Date>DATEstatic Serializer<java.lang.Double>DOUBLEstatic Serializer<double[]>DOUBLE_ARRAYSerializesdouble[]it adds header which contains size informationstatic Serializer<java.lang.Float>FLOATstatic Serializer<float[]>FLOAT_ARRAYstatic Serializer<java.lang.Object>ILLEGAL_ACCESSAlways throwsIllegalAccessErrorwhen invoked.static Serializer<int[]>INT_ARRAYSerializesint[]it adds header which contains size informationstatic Serializer<java.lang.Integer>INTEGERSerializes Integer into 4 bytes, used mainly for testing.static Serializer<java.lang.Integer>INTEGER_PACKEDPacks positive Integer, so smaller positive values occupy less than 4 bytes.static Serializer<java.lang.Integer>INTEGER_PACKED_ZIGZAGpacks Integer so small values occupy less than 4 bytes.static Serializer<java.lang.Object>JAVASerializer which uses standard Java Serialization withObjectInputStreamandObjectOutputStreamstatic Serializer<java.lang.Long>LONGSerializes Long into 8 bytes, used mainly for testing.static Serializer<long[]>LONG_ARRAYSerializeslong[]it adds header which contains size informationstatic Serializer<java.lang.Long>LONG_PACKEDPacks positive LONG, so smaller positive values occupy less than 8 bytes.static Serializer<java.lang.Long>LONG_PACKED_ZIGZAGpacks Long so small values occupy less than 8 bytes.static Serializer<java.lang.Long>RECIDPacks recid + it adds 3bits checksum.static Serializer<long[]>RECID_ARRAYstatic Serializer<java.lang.Short>SHORTstatic Serializer<short[]>SHORT_ARRAYstatic Serializer<java.lang.String>STRINGSerializes strings using UTF8 encoding.static Serializer<java.lang.String>STRING_ASCIISerializes strings using ASCII encoding (8 bit character).static Serializer<java.lang.String>STRING_INTERNSerializes strings using UTF8 encoding.static Serializer<java.lang.String>STRING_NOSIZESerializes strings using UTF8 encoding.static Serializer<java.lang.String>STRING_XXHASHSerializes strings using UTF8 encoding.static Serializer<java.util.UUID>UUIDSerializersUUIDclass
-
Constructor Summary
Constructors Constructor and Description Serializer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description abstract Adeserialize(java.io.DataInput in, int available)Deserialize the content of an object from a DataInput.booleanequals(A a1, A a2)intfixedSize()Data could be serialized into record with variable size or fixed size.BTreeKeySerializergetBTreeKeySerializer(java.util.Comparator comparator)inthashCode(A a, int seed)booleanisTrusted()MapDB has relax record size boundary checking.abstract voidserialize(java.io.DataOutput out, A value)Serialize the content of an object into a ObjectOutputjava.lang.ObjectvalueArrayCopyOfRange(java.lang.Object vals, int from, int to)java.lang.ObjectvalueArrayDeleteValue(java.lang.Object vals, int pos)java.lang.ObjectvalueArrayDeserialize(java.io.DataInput in, int size)java.lang.ObjectvalueArrayEmpty()java.lang.ObjectvalueArrayFromArray(java.lang.Object[] objects)AvalueArrayGet(java.lang.Object vals, int pos)java.lang.ObjectvalueArrayPut(java.lang.Object vals, int pos, A newValue)voidvalueArraySerialize(java.io.DataOutput out, java.lang.Object vals)intvalueArraySize(java.lang.Object vals)java.lang.ObjectvalueArrayUpdateVal(java.lang.Object vals, int pos, A newValue)
-
-
-
Field Detail
-
CHAR
public static final Serializer<java.lang.Character> CHAR
-
STRING_XXHASH
public static final Serializer<java.lang.String> STRING_XXHASH
Serializes strings using UTF8 encoding. Stores string size so can be used as collection serializer. Does not handle null values
Unlike
STRINGthis method hashes String with more reliable XXHash.
-
STRING
public static final Serializer<java.lang.String> STRING
Serializes strings using UTF8 encoding. Stores string size so can be used as collection serializer. Does not handle null values
-
STRING_INTERN
public static final Serializer<java.lang.String> STRING_INTERN
Serializes strings using UTF8 encoding. Deserialized String is internedString.intern(), so it could save some memory. Stores string size so can be used as collection serializer. Does not handle null values
-
STRING_ASCII
public static final Serializer<java.lang.String> STRING_ASCII
Serializes strings using ASCII encoding (8 bit character). Is faster compared to UTF8 encoding. Stores string size so can be used as collection serializer. Does not handle null values
-
STRING_NOSIZE
public static final Serializer<java.lang.String> STRING_NOSIZE
Serializes strings using UTF8 encoding. Used mainly for testing. Does not handle null values.
-
LONG
public static final Serializer<java.lang.Long> LONG
Serializes Long into 8 bytes, used mainly for testing. Does not handle null values.
-
LONG_PACKED
public static final Serializer<java.lang.Long> LONG_PACKED
Packs positive LONG, so smaller positive values occupy less than 8 bytes. Large and negative values could occupy 8 or 9 bytes.
-
LONG_PACKED_ZIGZAG
public static final Serializer<java.lang.Long> LONG_PACKED_ZIGZAG
packs Long so small values occupy less than 8 bytes. Large (positive and negative) values could occupy more 8 to 9 bytes. It uses zigzag conversion before packing, number is multiplied by two, with last bite indicating negativity.
-
INTEGER
public static final Serializer<java.lang.Integer> INTEGER
Serializes Integer into 4 bytes, used mainly for testing. Does not handle null values.
-
INTEGER_PACKED
public static final Serializer<java.lang.Integer> INTEGER_PACKED
Packs positive Integer, so smaller positive values occupy less than 4 bytes. Large and negative values could occupy 4 or 5 bytes.
-
INTEGER_PACKED_ZIGZAG
public static final Serializer<java.lang.Integer> INTEGER_PACKED_ZIGZAG
packs Integer so small values occupy less than 4 bytes. Large (positive and negative) values could occupy more 4 to 5 bytes. It uses zigzag conversion before packing, number is multiplied by two, with last bite indicating negativity.
-
BOOLEAN
public static final Serializer<java.lang.Boolean> BOOLEAN
-
RECID
public static final Serializer<java.lang.Long> RECID
Packs recid + it adds 3bits checksum.
-
RECID_ARRAY
public static final Serializer<long[]> RECID_ARRAY
-
ILLEGAL_ACCESS
public static final Serializer<java.lang.Object> ILLEGAL_ACCESS
Always throwsIllegalAccessErrorwhen invoked. Useful for testing and assertions.
-
BYTE_ARRAY
public static final Serializer<byte[]> BYTE_ARRAY
Serializesbyte[]it adds header which contains size information
-
BYTE_ARRAY_NOSIZE
public static final Serializer<byte[]> BYTE_ARRAY_NOSIZE
Serializesbyte[]directly into underlying store It does not store size, so it can not be used in Maps and other collections.
-
CHAR_ARRAY
public static final Serializer<char[]> CHAR_ARRAY
Serializeschar[]it adds header which contains size information
-
INT_ARRAY
public static final Serializer<int[]> INT_ARRAY
Serializesint[]it adds header which contains size information
-
LONG_ARRAY
public static final Serializer<long[]> LONG_ARRAY
Serializeslong[]it adds header which contains size information
-
DOUBLE_ARRAY
public static final Serializer<double[]> DOUBLE_ARRAY
Serializesdouble[]it adds header which contains size information
-
JAVA
public static final Serializer<java.lang.Object> JAVA
Serializer which uses standard Java Serialization withObjectInputStreamandObjectOutputStream
-
UUID
public static final Serializer<java.util.UUID> UUID
SerializersUUIDclass
-
BYTE
public static final Serializer<java.lang.Byte> BYTE
-
FLOAT
public static final Serializer<java.lang.Float> FLOAT
-
DOUBLE
public static final Serializer<java.lang.Double> DOUBLE
-
SHORT
public static final Serializer<java.lang.Short> SHORT
-
BOOLEAN_ARRAY
public static final Serializer<boolean[]> BOOLEAN_ARRAY
-
SHORT_ARRAY
public static final Serializer<short[]> SHORT_ARRAY
-
FLOAT_ARRAY
public static final Serializer<float[]> FLOAT_ARRAY
-
BIG_INTEGER
public static final Serializer<java.math.BigInteger> BIG_INTEGER
-
BIG_DECIMAL
public static final Serializer<java.math.BigDecimal> BIG_DECIMAL
-
CLASS
public static final Serializer<java.lang.Class<?>> CLASS
-
DATE
public static final Serializer<java.util.Date> DATE
-
BASIC
public static final Serializer<java.lang.Object> BASIC
Basic serializer for most classes injava.langandjava.utilpackages. It does not handle custom POJO classes. It also does not handle classes which require access toDBitself.
-
-
Method Detail
-
serialize
public abstract void serialize(java.io.DataOutput out, A value) throws java.io.IOExceptionSerialize the content of an object into a ObjectOutput- Parameters:
out- ObjectOutput to save object intovalue- Object to serialize- Throws:
java.io.IOException- in case of IO error
-
deserialize
public abstract A deserialize(java.io.DataInput in, int available) throws java.io.IOException
Deserialize the content of an object from a DataInput.- Parameters:
in- to read serialized data fromavailable- how many bytes are available in DataInput for reading, may be -1 (in streams) or 0 (null).- Returns:
- deserialized object
- Throws:
java.io.IOException- in case of IO error
-
fixedSize
public int fixedSize()
Data could be serialized into record with variable size or fixed size. Some optimizations can be applied to serializers with fixed size- Returns:
- fixed size or -1 for variable size
-
isTrusted
public boolean isTrusted()
MapDB has relax record size boundary checking. It expect deserializer to read exactly as many bytes as were writen during serialization. If deserializer reads more bytes 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 store, but must copy them into separate
byte[]. So zero copy optimalizations is disabled by default, and must be explicitly enabled here.This flag indicates if this serializer was 'verified' to read as many bytes as it writes. It should be also much better tested etc.
- Returns:
- true if this serializer is well tested and writes as many bytes as it reads.
-
hashCode
public int hashCode(A a, int seed)
-
valueArraySerialize
public void valueArraySerialize(java.io.DataOutput out, java.lang.Object vals) throws java.io.IOException- Throws:
java.io.IOException
-
valueArrayDeserialize
public java.lang.Object valueArrayDeserialize(java.io.DataInput in, int size) throws java.io.IOException- Throws:
java.io.IOException
-
valueArrayGet
public A valueArrayGet(java.lang.Object vals, int pos)
-
valueArraySize
public int valueArraySize(java.lang.Object vals)
-
valueArrayEmpty
public java.lang.Object valueArrayEmpty()
-
valueArrayPut
public java.lang.Object valueArrayPut(java.lang.Object vals, int pos, A newValue)
-
valueArrayUpdateVal
public java.lang.Object valueArrayUpdateVal(java.lang.Object vals, int pos, A newValue)
-
valueArrayFromArray
public java.lang.Object valueArrayFromArray(java.lang.Object[] objects)
-
valueArrayCopyOfRange
public java.lang.Object valueArrayCopyOfRange(java.lang.Object vals, int from, int to)
-
valueArrayDeleteValue
public java.lang.Object valueArrayDeleteValue(java.lang.Object vals, int pos)
-
getBTreeKeySerializer
public BTreeKeySerializer getBTreeKeySerializer(java.util.Comparator comparator)
-
-
DataMelt 3.0 © DataMelt by jWork.ORG