org.mapdb
Class SerializerBase

java.lang.Object
  extended by org.mapdb.SerializerBase
All Implemented Interfaces:
Serializer<Object>
Direct Known Subclasses:
SerializerPojo

public class SerializerBase
extends Object
implements Serializer<Object>

Serializer which uses 'header byte' to serialize/deserialize most of classes from 'java.lang' and 'java.util' packages.

Author:
Jan Kotek

Nested Class Summary
protected static class SerializerBase.FastArrayList<K>
          Utility class similar to ArrayList, but with fast identity search.
protected static interface SerializerBase.Header
          Header byte, is used at start of each record to indicate data type WARNING !!! values bellow must be unique !!!!!
protected static interface SerializerBase.HeaderMapDB
           
protected static class SerializerBase.singletons
           
 
Nested classes/interfaces inherited from interface org.mapdb.Serializer
Serializer.CompressionWrapper<E>
 
Field Summary
protected static String EMPTY_STRING
           
 
Fields inherited from interface org.mapdb.Serializer
BASIC, BOOLEAN, BYTE_ARRAY, BYTE_ARRAY_NOSIZE, CHAR_ARRAY, DOUBLE_ARRAY, ILLEGAL_ACCESS, INT_ARRAY, INTEGER, JAVA, LONG, LONG_ARRAY, STRING, STRING_ASCII, STRING_INTERN, STRING_NOSIZE, UUID
 
Constructor Summary
SerializerBase()
           
 
Method Summary
static void assertSerializable(Object o)
           
protected static byte[] booleanToByteArray(boolean[] bool)
          Builds a byte array from the array of booleans, compressing up to 8 booleans per byte.
 Object deserialize(DataInput is, int capacity)
          Deserialize the content of an object from a DataInput.
 Object deserialize(DataInput is, SerializerBase.FastArrayList<Object> objectStack)
           
protected  Class deserializeClass(DataInput is)
           
protected  Object deserializeMapDB(DataInput is, SerializerBase.FastArrayList<Object> objectStack)
           
protected  Object deserializeUnknownHeader(DataInput is, int head, SerializerBase.FastArrayList<Object> objectStack)
          override this method to extend SerializerBase functionality
 int fixedSize()
          Data could be serialized into record with variable size or fixed size.
protected  Engine getEngine()
           
protected static boolean[] readBooleanArray(int numBools, DataInput is)
          Unpacks an integer from the DataInput indicating the number of booleans that are compressed.
 void serialize(DataOutput out, Object obj)
          Serialize the content of an object into a ObjectOutput
 void serialize(DataOutput out, Object obj, SerializerBase.FastArrayList<Object> objectStack)
           
protected  void serializeClass(DataOutput out, Class clazz)
           
protected  void serializeUnknownObject(DataOutput out, Object obj, SerializerBase.FastArrayList<Object> objectStack)
          override this method to extend SerializerBase functionality
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STRING

protected static final String EMPTY_STRING
See Also:
Constant Field Values
Constructor Detail

SerializerBase

public SerializerBase()
Method Detail

serialize

public void serialize(DataOutput out,
                      Object obj)
               throws IOException
Description copied from interface: Serializer
Serialize the content of an object into a ObjectOutput

Specified by:
serialize in interface Serializer<Object>
Parameters:
out - ObjectOutput to save object into
obj - Object to serialize
Throws:
IOException

serialize

public void serialize(DataOutput out,
                      Object obj,
                      SerializerBase.FastArrayList<Object> objectStack)
               throws IOException
Throws:
IOException

serializeClass

protected void serializeClass(DataOutput out,
                              Class clazz)
                       throws IOException
Throws:
IOException

deserialize

public Object deserialize(DataInput is,
                          int capacity)
                   throws IOException
Description copied from interface: Serializer
Deserialize the content of an object from a DataInput.

Specified by:
deserialize in interface Serializer<Object>
Parameters:
is - to read serialized data from
capacity - how many bytes are available in DataInput for reading, may be -1 (in streams) or 0 (null).
Returns:
deserialized object
Throws:
IOException

deserialize

public Object deserialize(DataInput is,
                          SerializerBase.FastArrayList<Object> objectStack)
                   throws IOException
Throws:
IOException

assertSerializable

public static void assertSerializable(Object o)

deserializeMapDB

protected Object deserializeMapDB(DataInput is,
                                  SerializerBase.FastArrayList<Object> objectStack)
                           throws IOException
Throws:
IOException

getEngine

protected Engine getEngine()

deserializeClass

protected Class deserializeClass(DataInput is)
                          throws IOException
Throws:
IOException

serializeUnknownObject

protected void serializeUnknownObject(DataOutput out,
                                      Object obj,
                                      SerializerBase.FastArrayList<Object> objectStack)
                               throws IOException
override this method to extend SerializerBase functionality

Throws:
IOException

deserializeUnknownHeader

protected Object deserializeUnknownHeader(DataInput is,
                                          int head,
                                          SerializerBase.FastArrayList<Object> objectStack)
                                   throws IOException
override this method to extend SerializerBase functionality

Throws:
IOException

booleanToByteArray

protected static byte[] booleanToByteArray(boolean[] bool)
Builds a byte array from the array of booleans, compressing up to 8 booleans per byte. Author of this method is Chris Alexander.

Parameters:
bool - The booleans to be compressed.
Returns:
The fully compressed byte array.

readBooleanArray

protected static boolean[] readBooleanArray(int numBools,
                                            DataInput is)
                                     throws IOException
Unpacks an integer from the DataInput indicating the number of booleans that are compressed. It then calculates the number of bytes, reads them in, and decompresses and converts them into an array of booleans using the toBooleanArray(byte[]); method. The array of booleans are trimmed to numBools elements. This is necessary in situations where the number of booleans is not a multiple of 8. Author of this method is Chris Alexander.

Returns:
The boolean array decompressed from the bytes read in.
Throws:
IOException - If an error occurred while reading.

fixedSize

public int fixedSize()
Description copied from interface: Serializer
Data could be serialized into record with variable size or fixed size. Some optimizations can be applied to serializers with fixed size

Specified by:
fixedSize in interface Serializer<Object>
Returns:
fixed size or -1 for variable size


Copyright © 2014. All Rights Reserved.