|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.objects.nio.BinarySerializator
public abstract class BinarySerializator
This class provides a framework for binary serialization
of objects.
It operates on any BinaryInput
/BinaryOutput
.
BufferInputStream
,
BufferOutputStream
,
ChannelInputStream
,
ChannelOutputStream
Field Summary | |
---|---|
protected static java.util.logging.Logger |
log
Logger for serializators |
Constructor Summary | |
---|---|
BinarySerializator()
|
Method Summary | ||
---|---|---|
protected abstract int |
getBinarySize(BinarySerializable object)
Returns the size of the binary-serialized object in bytes. |
|
int |
getBinarySize(boolean[] array)
Returns the size of the (binary) serialized boolean array in bytes. |
|
int |
getBinarySize(byte[] array)
Returns the size of the (binary) serialized byte array in bytes. |
|
int |
getBinarySize(double[] array)
Returns the size of the (binary) serialized double array in bytes. |
|
int |
getBinarySize(float[] array)
Returns the size of the (binary) serialized float array in bytes. |
|
int |
getBinarySize(char[] array)
Returns the size of the (binary) serialized char array in bytes. |
|
int |
getBinarySize(int[] array)
Returns the size of the (binary) serialized int array in bytes. |
|
int |
getBinarySize(long[] array)
Returns the size of the (binary) serialized long array in bytes. |
|
int |
getBinarySize(java.lang.Object object)
Returns the size of the (binary) serialized object in bytes. |
|
int |
getBinarySize(short[] array)
Returns the size of the (binary) serialized short array in bytes. |
|
int |
getBinarySize(java.lang.String string)
Returns the size of the (binary) serialized String in bytes. |
|
protected static
|
getNativeSerializableConstructor(java.lang.Class<T> objectClass)
Returns a native-serializable constructor for objectClass . |
|
protected static java.lang.reflect.Method |
getNativeSerializableFactoryMethod(java.lang.Class<?> objectClass)
Returns a native-serializable factory method for objectClass . |
|
protected static long |
getSerialVersionUID(java.lang.Class<?> classToCheck)
Returns the value of the serialVersionUID field for the
specified class. |
|
protected static int |
getSerialVersionUIDHash(java.lang.Class<?> classToCheck)
Returns the hash code for value of the serialVersionUID
field of the specified class. |
|
boolean |
readBoolean(BinaryInput input)
Returns a boolean value read from the specified input. |
|
boolean[] |
readBooleanArray(BinaryInput input)
Returns a boolean array read from the specified input. |
|
byte |
readByte(BinaryInput input)
Returns a byte value read from the specified input. |
|
byte[] |
readByteArray(BinaryInput input)
Returns a byte array read from the specified input. |
|
double |
readDouble(BinaryInput input)
Returns a double value read from the specified input. |
|
double[] |
readDoubleArray(BinaryInput input)
Returns a double array read from the specified input. |
|
float |
readFloat(BinaryInput input)
Returns a float value read from the specified input. |
|
float[] |
readFloatArray(BinaryInput input)
Returns a float array read from the specified input. |
|
char |
readChar(BinaryInput input)
Returns a char value read from the specified input. |
|
char[] |
readCharArray(BinaryInput input)
Returns a char array read from the specified input. |
|
int |
readInt(BinaryInput input)
Returns a int value read from the specified input. |
|
int[] |
readIntArray(BinaryInput input)
Returns a int array read from the specified input. |
|
long |
readLong(BinaryInput input)
Returns a long value read from the specified input. |
|
long[] |
readLongArray(BinaryInput input)
Returns a long array read from the specified input. |
|
protected static java.lang.Object |
readObject(BinaryInput input,
BinarySerializator serializator,
java.lang.reflect.Constructor constructor,
java.lang.reflect.Method factoryMethod)
Reads an instance created by constructor or factoryMethod
from the input buffer. |
|
|
readObject(BinaryInput input,
java.lang.Class<E> expectedClass)
Reads an instance from the input using this serializator. |
|
protected abstract
|
readObjectImpl(BinaryInput input,
java.lang.Class<E> expectedClass)
Reads an instance using the proper constructor/factory method as specified by this serializator. |
|
protected int |
readObjectSize(BinaryInput input)
Read the size of the object at the current position of the buffer. |
|
short |
readShort(BinaryInput input)
Returns a short value read from the specified input. |
|
short[] |
readShortArray(BinaryInput input)
Returns a short array read from the specified input. |
|
java.lang.String |
readString(BinaryInput input)
Returns a String read from the specified input. |
|
int |
skipObject(BinaryInput stream,
boolean skipDeleted)
Skip the object at the current position of the stream. |
|
protected abstract int |
write(BinaryOutput output,
BinarySerializable object)
Writes object to this output buffer using binary serialization. |
|
int |
write(BinaryOutput output,
boolean value)
Writes a boolean value to the specified output. |
|
int |
write(BinaryOutput output,
boolean[] array)
Writes a boolean array to the specified output. |
|
int |
write(BinaryOutput output,
boolean[] array,
int index,
int length)
Writes a boolean array to the specified output. |
|
int |
write(BinaryOutput output,
byte value)
Writes a byte value to the specified output. |
|
int |
write(BinaryOutput output,
byte[] array)
Writes a byte array to the specified output. |
|
int |
write(BinaryOutput output,
byte[] array,
int index,
int length)
Writes a byte array to the specified output. |
|
int |
write(BinaryOutput output,
double value)
Writes a double value to the specified output. |
|
int |
write(BinaryOutput output,
double[] array)
Writes a double array to the specified output. |
|
int |
write(BinaryOutput output,
double[] array,
int index,
int length)
Writes a double array to the specified output. |
|
int |
write(BinaryOutput output,
float value)
Writes a float value to the specified output. |
|
int |
write(BinaryOutput output,
float[] array)
Writes a float array to the specified output. |
|
int |
write(BinaryOutput output,
float[] array,
int index,
int length)
Writes a float array to the specified output. |
|
int |
write(BinaryOutput output,
char value)
Writes a char value to the specified output. |
|
int |
write(BinaryOutput output,
char[] array)
Writes a char array to the specified output. |
|
int |
write(BinaryOutput output,
char[] array,
int index,
int length)
Writes a char array to the specified output. |
|
int |
write(BinaryOutput output,
int value)
Writes a int value to the specified output. |
|
int |
write(BinaryOutput output,
int[] array)
Writes a int array to the specified output. |
|
int |
write(BinaryOutput output,
int[] array,
int index,
int length)
Writes a int array to the specified output. |
|
int |
write(BinaryOutput output,
long value)
Writes a long value to the specified output. |
|
int |
write(BinaryOutput output,
long[] array)
Writes a long array to the specified output. |
|
int |
write(BinaryOutput output,
long[] array,
int index,
int length)
Writes a long array to the specified output. |
|
int |
write(BinaryOutput output,
java.lang.Object object)
Writes object to the provided output buffer. |
|
int |
write(BinaryOutput output,
short value)
Writes a short value to the specified output. |
|
int |
write(BinaryOutput output,
short[] array)
Writes a short array to the specified output. |
|
int |
write(BinaryOutput output,
short[] array,
int index,
int length)
Writes a short array to the specified output. |
|
int |
write(BinaryOutput output,
java.lang.String string)
Writes a String to the specified output. |
|
BufferOutputStream |
write(java.lang.Object object,
boolean bufferDirect)
Writes object to a new buffer output stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.util.logging.Logger log
Constructor Detail |
---|
public BinarySerializator()
Method Detail |
---|
public int write(BinaryOutput output, boolean value) throws java.io.IOException
boolean
value to the specified output.
output
- the output buffer to write the value intovalue
- the boolean
value to be written
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, byte value) throws java.io.IOException
byte
value to the specified output.
output
- the output buffer to write the value intovalue
- the byte
value to be written
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, short value) throws java.io.IOException
short
value to the specified output.
output
- the output buffer to write the value intovalue
- the short
value to be written
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, char value) throws java.io.IOException
char
value to the specified output.
output
- the output buffer to write the value intovalue
- the char
value to be written
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, int value) throws java.io.IOException
int
value to the specified output.
output
- the output buffer to write the value intovalue
- the int
value to be written
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, long value) throws java.io.IOException
long
value to the specified output.
output
- the output buffer to write the value intovalue
- the long
value to be written
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, float value) throws java.io.IOException
float
value to the specified output.
output
- the output buffer to write the value intovalue
- the float
value to be written
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, double value) throws java.io.IOException
double
value to the specified output.
output
- the output buffer to write the value intovalue
- the double
value to be written
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, boolean[] array, int index, int length) throws java.io.IOException, java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
boolean
array to the specified output.
output
- the output buffer to write the array intoarray
- the boolean array to writeindex
- the start index in the boolean arraylength
- the number of array items to write
java.io.IOException
- if there was an I/O error
java.lang.NullPointerException
- if the specified array is null
java.lang.IndexOutOfBoundsException
- if the index
or length
are invalid for the specified arraypublic int write(BinaryOutput output, boolean[] array) throws java.io.IOException
boolean
array to the specified output.
output
- the output buffer to write the array intoarray
- the boolean array to write
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, byte[] array, int index, int length) throws java.io.IOException, java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
byte
array to the specified output.
output
- the output buffer to write the array intoarray
- the byte array to writeindex
- the start index in the byte arraylength
- the number of array items to write
java.io.IOException
- if there was an I/O error
java.lang.NullPointerException
- if the specified array is null
java.lang.IndexOutOfBoundsException
- if the index
or length
are invalid for the specified arraypublic int write(BinaryOutput output, byte[] array) throws java.io.IOException
byte
array to the specified output.
output
- the output buffer to write the array intoarray
- the byte array to write
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, short[] array, int index, int length) throws java.io.IOException, java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
short
array to the specified output.
output
- the output buffer to write the array intoarray
- the short array to writeindex
- the start index in the short arraylength
- the number of array items to write
java.io.IOException
- if there was an I/O error
java.lang.NullPointerException
- if the specified array is null
java.lang.IndexOutOfBoundsException
- if the index
or length
are invalid for the specified arraypublic int write(BinaryOutput output, short[] array) throws java.io.IOException
short
array to the specified output.
output
- the output buffer to write the array intoarray
- the short array to write
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, char[] array, int index, int length) throws java.io.IOException, java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
char
array to the specified output.
output
- the output buffer to write the array intoarray
- the char array to writeindex
- the start index in the char arraylength
- the number of array items to write
java.io.IOException
- if there was an I/O error
java.lang.NullPointerException
- if the specified array is null
java.lang.IndexOutOfBoundsException
- if the index
or length
are invalid for the specified arraypublic int write(BinaryOutput output, char[] array) throws java.io.IOException
char
array to the specified output.
output
- the output buffer to write the array intoarray
- the char array to write
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, int[] array, int index, int length) throws java.io.IOException, java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
int
array to the specified output.
output
- the output buffer to write the array intoarray
- the int array to writeindex
- the start index in the int arraylength
- the number of array items to write
java.io.IOException
- if there was an I/O error
java.lang.NullPointerException
- if the specified array is null
java.lang.IndexOutOfBoundsException
- if the index
or length
are invalid for the specified arraypublic int write(BinaryOutput output, int[] array) throws java.io.IOException
int
array to the specified output.
output
- the output buffer to write the array intoarray
- the int array to write
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, long[] array, int index, int length) throws java.io.IOException, java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
long
array to the specified output.
output
- the output buffer to write the array intoarray
- the long array to writeindex
- the start index in the long arraylength
- the number of array items to write
java.io.IOException
- if there was an I/O error
java.lang.NullPointerException
- if the specified array is null
java.lang.IndexOutOfBoundsException
- if the index
or length
are invalid for the specified arraypublic int write(BinaryOutput output, long[] array) throws java.io.IOException
long
array to the specified output.
output
- the output buffer to write the array intoarray
- the long array to write
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, float[] array, int index, int length) throws java.io.IOException, java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
float
array to the specified output.
output
- the output buffer to write the array intoarray
- the float array to writeindex
- the start index in the float arraylength
- the number of array items to write
java.io.IOException
- if there was an I/O error
java.lang.NullPointerException
- if the specified array is null
java.lang.IndexOutOfBoundsException
- if the index
or length
are invalid for the specified arraypublic int write(BinaryOutput output, float[] array) throws java.io.IOException
float
array to the specified output.
output
- the output buffer to write the array intoarray
- the float array to write
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, double[] array, int index, int length) throws java.io.IOException, java.lang.NullPointerException, java.lang.IndexOutOfBoundsException
double
array to the specified output.
output
- the output buffer to write the array intoarray
- the double array to writeindex
- the start index in the double arraylength
- the number of array items to write
java.io.IOException
- if there was an I/O error
java.lang.NullPointerException
- if the specified array is null
java.lang.IndexOutOfBoundsException
- if the index
or length
are invalid for the specified arraypublic int write(BinaryOutput output, double[] array) throws java.io.IOException
double
array to the specified output.
output
- the output buffer to write the array intoarray
- the double array to write
java.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, java.lang.String string) throws java.io.IOException
String
to the specified output.
output
- the buffer to write the string intostring
- the String
to be written
java.io.IOException
- if there was an I/O errorpublic final int write(BinaryOutput output, java.lang.Object object) throws java.io.IOException
object
to the provided output buffer.
If the object implements BinarySerializable
interface, it
is binary-serialized. Otherwise, a standard Java serialization
is used.
output
- the buffer to write the object toobject
- the object to write
java.io.IOException
- if there was an error using flushChannelpublic final BufferOutputStream write(java.lang.Object object, boolean bufferDirect) throws java.io.IOException
object
to a new buffer output stream.
If the object implements BinarySerializable
interface, it
is binary-serialized. Otherwise, a standard Java serialization
is used.
object
- the object to writebufferDirect
- the type of buffer to use (direct or array-backed)
java.io.IOException
- if there was an error using flushChannelprotected abstract int write(BinaryOutput output, BinarySerializable object) throws java.io.IOException
object
to this output buffer using binary serialization.
The following rules must hold:
getBinarySize(BinarySerializable)
readObject
method must read the serialized data exactly as written by this method
output
- the buffer to write the object toobject
- the object to write
java.io.IOException
- if there was an error using flushChannelpublic boolean readBoolean(BinaryInput input) throws java.io.IOException
boolean
value read from the specified input.
input
- the input buffer to read the value from
boolean
value read from the input
java.io.IOException
- if there was an I/O errorpublic byte readByte(BinaryInput input) throws java.io.IOException
byte
value read from the specified input.
input
- the input buffer to read the value from
byte
value read from the input
java.io.IOException
- if there was an I/O errorpublic short readShort(BinaryInput input) throws java.io.IOException
short
value read from the specified input.
input
- the input buffer to read the value from
short
value read from the input
java.io.IOException
- if there was an I/O errorpublic char readChar(BinaryInput input) throws java.io.IOException
char
value read from the specified input.
input
- the input buffer to read the value from
char
value read from the input
java.io.IOException
- if there was an I/O errorpublic int readInt(BinaryInput input) throws java.io.IOException
int
value read from the specified input.
input
- the input buffer to read the value from
int
value read from the input
java.io.IOException
- if there was an I/O errorpublic long readLong(BinaryInput input) throws java.io.IOException
long
value read from the specified input.
input
- the input buffer to read the value from
long
value read from the input
java.io.IOException
- if there was an I/O errorpublic float readFloat(BinaryInput input) throws java.io.IOException
float
value read from the specified input.
input
- the input buffer to read the value from
float
value read from the input
java.io.IOException
- if there was an I/O errorpublic double readDouble(BinaryInput input) throws java.io.IOException
double
value read from the specified input.
input
- the input buffer to read the value from
double
value read from the input
java.io.IOException
- if there was an I/O errorpublic boolean[] readBooleanArray(BinaryInput input) throws java.io.IOException
boolean
array read from the specified input.
input
- the buffer to read the array from
boolean
array read from the input
java.io.IOException
- if there was an I/O errorpublic byte[] readByteArray(BinaryInput input) throws java.io.IOException
byte
array read from the specified input.
input
- the buffer to read the array from
byte
array read from the input
java.io.IOException
- if there was an I/O errorpublic short[] readShortArray(BinaryInput input) throws java.io.IOException
short
array read from the specified input.
input
- the buffer to read the array from
short
array read from the input
java.io.IOException
- if there was an I/O errorpublic char[] readCharArray(BinaryInput input) throws java.io.IOException
char
array read from the specified input.
input
- the buffer to read the array from
char
array read from the input
java.io.IOException
- if there was an I/O errorpublic int[] readIntArray(BinaryInput input) throws java.io.IOException
int
array read from the specified input.
input
- the buffer to read the array from
int
array read from the input
java.io.IOException
- if there was an I/O errorpublic long[] readLongArray(BinaryInput input) throws java.io.IOException
long
array read from the specified input.
input
- the buffer to read the array from
long
array read from the input
java.io.IOException
- if there was an I/O errorpublic float[] readFloatArray(BinaryInput input) throws java.io.IOException
float
array read from the specified input.
input
- the buffer to read the array from
float
array read from the input
java.io.IOException
- if there was an I/O errorpublic double[] readDoubleArray(BinaryInput input) throws java.io.IOException
double
array read from the specified input.
input
- the buffer to read the array from
double
array read from the input
java.io.IOException
- if there was an I/O errorpublic java.lang.String readString(BinaryInput input) throws java.io.IOException
String
read from the specified input.
input
- the buffer to read the string from
String
read from the input
java.io.IOException
- if there was an I/O errorpublic final <E> E readObject(BinaryInput input, java.lang.Class<E> expectedClass) throws java.io.IOException, java.lang.IllegalArgumentException
input
using this serializator.
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 input
java.io.IOException
- if there was an I/O error
java.lang.IllegalArgumentException
- if the constructor or the factory method has a wrong prototypeprotected abstract <E> E readObjectImpl(BinaryInput input, java.lang.Class<E> expectedClass) throws java.io.IOException, java.lang.IllegalArgumentException
objectSize
bytes from the input
or throw an exceptionwrite method
has written them
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 input
java.io.IOException
- if there was an I/O error
java.lang.IllegalArgumentException
- if the constructor or the factory method has a wrong prototypeprotected static java.lang.Object readObject(BinaryInput input, BinarySerializator serializator, java.lang.reflect.Constructor constructor, java.lang.reflect.Method factoryMethod) throws java.io.IOException, java.lang.IllegalArgumentException
constructor
or factoryMethod
from the input buffer.
If both the constructor and the factory method are null,
standard Java deserialization
is used.
input
- the buffer to read the instance fromserializator
- the serializator used to write objectsconstructor
- the constructor
of the object class to readfactoryMethod
- the factory method
of the object class to read
java.io.IOException
- if there was an I/O error
java.lang.IllegalArgumentException
- if the constructor or the factory method has a wrong prototypepublic int getBinarySize(boolean[] array)
boolean
array in bytes.
The exact size including all overhead is returned.
array
- the array to get the size for
public int getBinarySize(byte[] array)
byte
array in bytes.
The exact size including all overhead is returned.
array
- the array to get the size for
public int getBinarySize(short[] array)
short
array in bytes.
The exact size including all overhead is returned.
array
- the array to get the size for
public int getBinarySize(char[] array)
char
array in bytes.
The exact size including all overhead is returned.
array
- the array to get the size for
public int getBinarySize(int[] array)
int
array in bytes.
The exact size including all overhead is returned.
array
- the array to get the size for
public int getBinarySize(long[] array)
long
array in bytes.
The exact size including all overhead is returned.
array
- the array to get the size for
public int getBinarySize(float[] array)
float
array in bytes.
The exact size including all overhead is returned.
array
- the array to get the size for
public int getBinarySize(double[] array)
double
array in bytes.
The exact size including all overhead is returned.
array
- the array to get the size for
public int getBinarySize(java.lang.String string)
String
in bytes.
The exact size including all overhead is returned.
string
- the string to get the size for
String
protected int readObjectSize(BinaryInput input) throws java.io.IOException
input
- the buffer from which to read the object size
java.io.IOException
- if there was an error reading from the input bufferpublic int skipObject(BinaryInput stream, boolean skipDeleted) throws java.io.IOException
stream
- the stream in which to skip an objectskipDeleted
- if true the deleted object are silently skipped (their sizes are not reported)
java.io.IOException
- if there was an error reading from the input streampublic final int getBinarySize(java.lang.Object object) throws java.lang.IllegalArgumentException
object
in bytes.
The exact size including all overhead is returned.
This method can be very slow if the standard Java serialization
is used on object, i.e. when the object does not implement the BinarySerializable
interface.
object
- the object to get the size for
object
java.lang.IllegalArgumentException
- if there was an error using Java standard serialization on the objectprotected abstract int getBinarySize(BinarySerializable object) throws java.lang.IllegalArgumentException
object
in bytes.
object
- the object to get the size for
object
java.lang.IllegalArgumentException
- if there was an error using Java standard serialization on the objectprotected static <T> java.lang.reflect.Constructor<T> getNativeSerializableConstructor(java.lang.Class<T> objectClass)
objectClass
.
The constructor should have the following prototype:
ClassConstructor(BinaryInput
input,BinarySerializator
serializator) throwsIOException
T
- the object class to constructobjectClass
- the object class to construct
objectClass
or null if there is no native-serializable constructorprotected static java.lang.reflect.Method getNativeSerializableFactoryMethod(java.lang.Class<?> objectClass)
objectClass
.
The factory method should have the following prototype:
ObjectClass binaryDeserialize(BinaryInput
input,BinarySerializator
serializator) throwsIOException
objectClass
- the object class to construct
objectClass
or null if there is no native-serializable factory methodprotected static long getSerialVersionUID(java.lang.Class<?> classToCheck) throws java.lang.NoSuchFieldException
serialVersionUID
field for the
specified class.
classToCheck
- the class for which to look-up the serial version
java.lang.NoSuchFieldException
- if the class does not have serial versionprotected static int getSerialVersionUIDHash(java.lang.Class<?> classToCheck)
serialVersionUID
field of the specified class.
classToCheck
- the class for which to look-up the serial version
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |