T
- default class used when reading serialized objectpublic class MultiClassSerializator<T> extends BinarySerializator implements java.io.Serializable
BinarySerializator
which works on
all classes. There is a cost of the class name and constructor/factory
method lookup when the objects are deserialized for other than the default
class.
This serializator checks the serialUIDs of the default class for changes.Modifier and Type | Field and Description |
---|---|
protected static byte |
CLASSNAME_SERIALIZATION
Constant indicating that the name of the class is written in the stream
|
protected java.lang.reflect.Constructor<?> |
constructor
The cached constructor for the default class
|
protected java.lang.Class<? extends T> |
defaultClass
The first class in the predefinedClasses is used as default
|
protected static byte |
DEFAULTCLASS_SERIALIZATION
Constant indicating that the default class is written in the stream
|
protected java.lang.reflect.Method |
factoryMethod
The cached factory method for the default class
|
protected static byte |
JAVA_SERIALIZATION
Constant indicating that the standard Java
serialization is used |
log
Constructor and Description |
---|
MultiClassSerializator(java.lang.Class<? extends T> defaultClass)
Creates a new instance of MultiClassSerializator.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this serializator.
|
protected int |
getBinarySize(BinarySerializable object)
Returns the size of the binary-serialized
object in bytes. |
protected int |
getClassIndex(BinarySerializable object)
Returns the index of the predefined class for this object.
|
protected java.lang.reflect.Constructor<?> |
getConstructor(byte flag,
java.lang.Class<?> objectClass)
Returns a constructor for the specified flag and object class.
|
java.lang.Class<? extends T> |
getDefaultClass()
Returns a default class that is used for deserialization when a class is not specified.
|
protected java.lang.reflect.Method |
getFactoryMethod(byte flag,
java.lang.Class<?> objectClass)
Returns a factory method for the specified flag and object class.
|
int |
hashCode()
Returns a hash code value for this serializator.
|
T |
readObject(BinaryInput input)
Reads an instance from the
input using this serializator. |
protected <E> E |
readObjectImpl(BinaryInput input,
java.lang.Class<E> expectedClass)
Reads an instance using the proper constructor/factory method.
|
protected int |
write(BinaryOutput output,
BinarySerializable object)
Writes
object to this output buffer using binary serialization. |
getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getNativeSerializableConstructor, getNativeSerializableFactoryMethod, getSerialVersionUID, getSerialVersionUIDHash, objectToBuffer, readBigInteger, readBoolean, readBooleanArray, readByte, readByteArray, readDouble, readDoubleArray, readEnum, readFloat, readFloatArray, readFromFile, readChar, readCharArray, readInt, readIntArray, readLong, readLongArray, readObject, readObject, readObjectSize, readShort, readShortArray, readString, readStringArray, skipObject, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, writeToFile
protected static final byte JAVA_SERIALIZATION
serialization
is usedprotected static final byte DEFAULTCLASS_SERIALIZATION
protected static final byte CLASSNAME_SERIALIZATION
protected final java.lang.Class<? extends T> defaultClass
protected final transient java.lang.reflect.Constructor<?> constructor
protected final transient java.lang.reflect.Method factoryMethod
public MultiClassSerializator(java.lang.Class<? extends T> defaultClass) throws java.lang.IllegalArgumentException
defaultClass
implements the BinarySerializable
interface,
the constructor/factory method is extracted for deserializing.
Otherwise a standard Java serialization will be used.
The constructor/factory method of the defaultClass
is cached.defaultClass
- the default class that is used for deserialization when a class is not specifiedjava.lang.IllegalArgumentException
- if there is an invalid value in predefinedClasses
public T readObject(BinaryInput input) throws java.io.IOException, java.lang.IllegalArgumentException
input
using this serializator.
The default
class that is expected to be in the buffer.input
- the buffer to read the instance fromjava.io.IOException
- if there was an I/O errorjava.lang.IllegalArgumentException
- if the constructor or the factory method has a wrong prototypeprotected int getBinarySize(BinarySerializable object) throws java.lang.IllegalArgumentException
object
in bytes.getBinarySize
in class BinarySerializator
object
- the object to get the size forobject
java.lang.IllegalArgumentException
- if there was an error using Java standard serialization on the objectprotected int write(BinaryOutput output, BinarySerializable object) throws java.io.IOException
BinarySerializator
object
to this output buffer using binary serialization.
The following rules must hold:
BinarySerializator.getBinarySize(BinarySerializable)
readObject
method must read the serialized data exactly as written by this methodwrite
in class BinarySerializator
output
- the buffer to write the object toobject
- the object to writejava.io.IOException
- if there was an error using flushChannelprotected <E> E readObjectImpl(BinaryInput input, java.lang.Class<E> expectedClass) throws java.io.IOException, java.lang.IllegalArgumentException
getConstructor(byte, java.lang.Class<?>)
and getFactoryMethod(byte, java.lang.Class<?>)
.
Finally, the object is deserialized using the constructor, the factory method
or standard Java serialization
.readObjectImpl
in class BinarySerializator
E
- the class that is expected to be in the inputinput
- the buffer to read the instance fromexpectedClass
- the class that is expected to be in the bufferjava.io.IOException
- if there was an I/O errorjava.lang.IllegalArgumentException
- if there was a problem getting a valid constructor/factory methodprotected java.lang.reflect.Constructor<?> getConstructor(byte flag, java.lang.Class<?> objectClass) throws java.lang.IllegalArgumentException
flag
- the type of deserialization (see constants)objectClass
- the class that is expected to be in the streamjava.lang.IllegalArgumentException
- if there was a problem getting the constructorprotected java.lang.reflect.Method getFactoryMethod(byte flag, java.lang.Class<?> objectClass) throws java.lang.IllegalArgumentException
flag
- the type of deserialization (see constants)objectClass
- the class that is expected to be in the streamjava.lang.IllegalArgumentException
- if there was a problem getting the factory methodprotected int getClassIndex(BinarySerializable object)
object
- the object whose class is looked uppublic java.lang.Class<? extends T> getDefaultClass()
public int hashCode()
defaultClass
.hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the reference object with which to comparetrue
if this serializator is the same as the obj
argument; false
otherwise.