Class ElsaSerializerBase
- All Implemented Interfaces:
ElsaSerializer
- Direct Known Subclasses:
ElsaSerializerPojo
Basic Elsa serializer and deserializer. It recognizes some 'java.lang.*' and 'java.util.*' classes such as Long, String, HashMap...
This serializer does not analyze class structure and fields. This functionality is in ElsaSerializerPojo
Internally it uses Map<Class,Serializer> to decide what way to serialize class and Map<HeaderByte, Deserializer>
to deserialize data.
If this serializer finds unknown class at graph traversal, it will pass it to
serializeUnknownObject(DataOutput, Object, ElsaStack) function for serialization.
By default this throws an NotSerializableException.
But this method can be overridden in subclasses to add extra functionality(ElsaSerializerPojo is subclass).
If this deserializer finds unknown Header Byte (binary data type), it will pass it to
deserializeUnknownHeader(DataInput, int, ElsaStack) function for deserialization.
By default this throws an IOException.
But this method can be overridden in subclasses to add extra functionality(ElsaSerializerPojo is subclass).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInterface internally used by Elsa to deserialize concrete Header Byte.protected static final classprotected static final classprotected final classalways returns single object without reading anythingprotected static final classprotected static interfaceHeader byte, is used at start of each record to indicate data type WARNING !!! values bellow must be unique !!!!!static classInterface internally used by Elsa to serialize concrete single class.protected static final classUser Serializers have designated Header Byte, followed by packed Int which identifies User Serializer. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ClassLoaderprotected static final ElsaSerializerBase.Deserializer<byte[]> protected final ElsaSerializerBase.Deserializer[]protected final intprotected final Map<Class, ElsaSerializerBase.Serializer> protected static final ElsaSerializerBase.Serializerprotected static final ElsaSerializerBase.Serializerprotected static final ElsaSerializerBase.Serializer<byte[]> protected static final ElsaSerializerBase.Serializerprotected static final ElsaSerializerBase.Serializerprotected static final ElsaSerializerBase.Serializerprotected static final ElsaSerializerBase.Serializerprotected static final ElsaSerializerBase.Serializerprotected static final ElsaSerializerBase.Serializerprotected static final ElsaSerializerBase.Serializerprotected static final ElsaSerializerBase.Serializerprotected static final ElsaSerializerBase.Serializerprotected final Object[]protected final IdentityHashMap<Object, Integer> protected final ElsaSerializerBase.Deserializer[] -
Constructor Summary
ConstructorsConstructorDescriptionElsaSerializerBase(ClassLoader classLoader, int objectStackType, Object[] singletons, Map<Class, ElsaSerializerBase.Serializer> userSer, Map<Class, Integer> userSerHeaders, Map<Integer, ElsaSerializerBase.Deserializer> userDeser) -
Method Summary
Modifier and TypeMethodDescription<E> Eclone(E value) Deep binary clone.protected static ClassLoaderdefaultClassLoaderIfNull(ClassLoader classLoader) <E> Edeserialize(DataInput input) Reads binary data from input and converts them into object instances.deserialize(DataInput in, ElsaStack objectStack) deserializeArrayList(DataInput is, ElsaStack objectStack) private Object[]deserializeArrayObject(DataInput is, ElsaStack objectStack) deserializeHashMap(DataInput is, ElsaStack objectStack) deserializeHashSet(DataInput is, ElsaStack objectStack) private LinkedHashMap<Object, Object> deserializeLinkedHashMap(DataInput is, ElsaStack objectStack) private LinkedHashSet<Object> deserializeLinkedHashSet(DataInput is, ElsaStack objectStack) private LinkedListdeserializeLinkedList(DataInput is, ElsaStack objectStack) private PropertiesdeserializeProperties(DataInput is, ElsaStack objectStack) protected ObjectdeserializeSingleton(DataInput is, ElsaStack objectStack) (package private) static StringdeserializeString(DataInput buf, int len) deserializeTreeMap(DataInput is, ElsaStack objectStack) deserializeTreeSet(DataInput is, ElsaStack objectStack) protected ObjectdeserializeUnknownHeader(DataInput is, int head, ElsaStack objectStack) override this method to extend ElsaSerializerBase functionalityprotected voidprotected voidinitSer()booleanChecks if given object is known to Elsa.protected Class<?> loadClassCached(String name) protected Class<?> loadClassCached(String name, ClassLoader classLoader) protected Classprotected ElsaStackprotected static boolean[]readBooleanArray(int numBools, DataInput is) Unpacks boolean[], each value in array is represented by single bitevoidserialize(DataOutput output, Object obj) Converts object instance into binary formvoidserialize(DataOutput out, Object obj, ElsaStack objectStack) protected voidserializeClass(DataOutput out, Class clazz) private voidserializeCollection(int header, DataOutput out, Object obj, ElsaStack objectStack) private voidserializeMap(int header, DataOutput out, Object obj, ElsaStack objectStack) voidserializeObjectArray(DataOutput out, Object[] b, ElsaStack objectStack) protected voidserializeUnknownObject(DataOutput out, Object obj, ElsaStack objectStack) override this method to extend ElsaSerializerBase functionalityprotected static voidwriteBooleanArray(DataOutput out, boolean[] bool) Writes boolean[] into output, each value in array is represented by single byte
-
Field Details
-
objectStackType
protected final int objectStackType -
singletons
-
singletonsReverse
-
ser
-
classCache
-
headerDeser
-
userDeser
-
classLoader
-
SER_STRING
-
SER_LONG_ARRAY
-
SER_INT_ARRAY
-
SER_DOUBLE
-
SER_FLOAT
-
SER_SHORT
-
SER_CHAR
-
SER_BYTE
-
SER_BOOLEAN
-
SER_LONG
-
SER_INT
-
SER_BYTE_ARRAY
-
DESER_BYTE_ARRAY
-
-
Constructor Details
-
ElsaSerializerBase
public ElsaSerializerBase() -
ElsaSerializerBase
public ElsaSerializerBase(ClassLoader classLoader, int objectStackType, Object[] singletons, Map<Class, ElsaSerializerBase.Serializer> userSer, Map<Class, Integer> userSerHeaders, Map<Integer, ElsaSerializerBase.Deserializer> userDeser)
-
-
Method Details
-
loadClassCached
- Throws:
ClassNotFoundException
-
loadClassCached
protected Class<?> loadClassCached(String name, ClassLoader classLoader) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
loadClassCachedUnchecked
-
defaultClassLoaderIfNull
-
initSer
protected void initSer() -
serializeObjectArray
public void serializeObjectArray(DataOutput out, Object[] b, ElsaStack objectStack) throws IOException - Throws:
IOException
-
initHeaderDeser
protected void initHeaderDeser() -
serialize
Description copied from interface:ElsaSerializerConverts object instance into binary form- Specified by:
serializein interfaceElsaSerializer- Parameters:
output- output into which binary data will be written while object is serializedobj- object instance to be serialized- Throws:
IOException- an exception from underlying stream
-
newElsaStack
-
clone
Description copied from interface:ElsaSerializerDeep binary clone. Serialize object into binary form, and then use data to deserialize it. Returned object should be equal to original, but is completely different instance.- Specified by:
clonein interfaceElsaSerializer- Type Parameters:
E- type of cloned object- Parameters:
value- object instance to be cloned- Returns:
- deep clone
- Throws:
IOException- an exception from underlying stream
-
serialize
- Throws:
IOException
-
serializeClass
- Throws:
IOException
-
serializeMap
private void serializeMap(int header, DataOutput out, Object obj, ElsaStack objectStack) throws IOException - Throws:
IOException
-
serializeCollection
private void serializeCollection(int header, DataOutput out, Object obj, ElsaStack objectStack) throws IOException - Throws:
IOException
-
deserializeString
- Throws:
IOException
-
deserialize
Description copied from interface:ElsaSerializerReads binary data from input and converts them into object instances.- Specified by:
deserializein interfaceElsaSerializer- Type Parameters:
E- type of deserialized object- Parameters:
input- input to read data from- Returns:
- deserialized object
- Throws:
IOException- an exception from underlying stream
-
deserialize
- Throws:
IOException
-
deserializeSingleton
- Throws:
IOException
-
deserializeArrayObject
- Throws:
IOException
-
deserializeArrayList
private ArrayList<Object> deserializeArrayList(DataInput is, ElsaStack objectStack) throws IOException - Throws:
IOException
-
deserializeLinkedList
- Throws:
IOException
-
deserializeHashSet
- Throws:
IOException
-
deserializeLinkedHashSet
private LinkedHashSet<Object> deserializeLinkedHashSet(DataInput is, ElsaStack objectStack) throws IOException - Throws:
IOException
-
deserializeTreeSet
- Throws:
IOException
-
deserializeTreeMap
private TreeMap<Object,Object> deserializeTreeMap(DataInput is, ElsaStack objectStack) throws IOException - Throws:
IOException
-
deserializeHashMap
private HashMap<Object,Object> deserializeHashMap(DataInput is, ElsaStack objectStack) throws IOException - Throws:
IOException
-
deserializeLinkedHashMap
private LinkedHashMap<Object,Object> deserializeLinkedHashMap(DataInput is, ElsaStack objectStack) throws IOException - Throws:
IOException
-
deserializeProperties
- Throws:
IOException
-
serializeUnknownObject
protected void serializeUnknownObject(DataOutput out, Object obj, ElsaStack objectStack) throws IOException override this method to extend ElsaSerializerBase functionality- Parameters:
out- put binary data hereobj- object to be serializedobjectStack- objectStack for handling backward references- Throws:
IOException- an exception from underlying stream
-
deserializeUnknownHeader
protected Object deserializeUnknownHeader(DataInput is, int head, ElsaStack objectStack) throws IOException override this method to extend ElsaSerializerBase functionality- Parameters:
is- read binary data from herehead- binary header read from input streamobjectStack- objectStack for handling backward references- Returns:
- deserialized object
- Throws:
ElsaException.UnknownHeaderByte- in default implementation if unknown Header ByteIOException- an exception from underlying stream
-
writeBooleanArray
Writes boolean[] into output, each value in array is represented by single byte- Parameters:
out- write binary data herebool- The booleans to be writen- Throws:
IOException- an exception from underlying stream
-
readBooleanArray
Unpacks boolean[], each value in array is represented by single bite- Parameters:
numBools- number of booleans to readis- read data from here- Returns:
- The boolean array decompressed from the bytes read in.
- Throws:
IOException- If an error occurred while reading.
-
isSerializable
Checks if given object is known to Elsa. If false is returned, Elsa will use less efficient field serializer.- Parameters:
o- object to be checked- Returns:
- true if mapdb knows howto serialize given object
-