public abstract class BinarySerializator
extends java.lang.Object
binary serialization
of objects.
It operates on any BinaryInput
/BinaryOutput
.Modifier and Type | Field and Description |
---|---|
protected static java.util.logging.Logger |
log
Logger for serializators
|
Constructor and Description |
---|
BinarySerializator() |
Modifier and Type | Method and Description |
---|---|
int |
getBinarySize(java.math.BigInteger value)
Returns the size of the (binary) serialized
BigInteger in bytes. |
protected abstract int |
getBinarySize(BinarySerializable object)
Returns the size of the binary-serialized
object in bytes. |
int |
getBinarySize(boolean value)
Returns the size of the (binary) serialized
boolean in bytes. |
int |
getBinarySize(boolean[] array)
Returns the size of the (binary) serialized
boolean array in bytes. |
int |
getBinarySize(boolean[] array,
int index,
int length)
Returns the size of the (binary) serialized
boolean array in bytes. |
int |
getBinarySize(byte value)
Returns the size of the (binary) serialized
byte in bytes. |
int |
getBinarySize(byte[] array)
Returns the size of the (binary) serialized
byte array in bytes. |
int |
getBinarySize(byte[] array,
int index,
int length)
Returns the size of the (binary) serialized
byte array in bytes. |
int |
getBinarySize(double value)
Returns the size of the (binary) serialized
double in bytes. |
int |
getBinarySize(double[] array)
Returns the size of the (binary) serialized
double array in bytes. |
int |
getBinarySize(double[] array,
int index,
int length)
Returns the size of the (binary) serialized
double array in bytes. |
int |
getBinarySize(java.lang.Enum<?> enumInstance)
Returns the size of the (binary) serialized
Enum in bytes. |
int |
getBinarySize(float value)
Returns the size of the (binary) serialized
float in bytes. |
int |
getBinarySize(float[] array)
Returns the size of the (binary) serialized
float array in bytes. |
int |
getBinarySize(float[] array,
int index,
int length)
Returns the size of the (binary) serialized
float array in bytes. |
int |
getBinarySize(char value)
Returns the size of the (binary) serialized
char in bytes. |
int |
getBinarySize(char[] array)
Returns the size of the (binary) serialized
char array in bytes. |
int |
getBinarySize(char[] array,
int index,
int length)
Returns the size of the (binary) serialized
char array in bytes. |
int |
getBinarySize(int value)
Returns the size of the (binary) serialized
int in bytes. |
int |
getBinarySize(int[] array)
Returns the size of the (binary) serialized
int array in bytes. |
int |
getBinarySize(int[] array,
int index,
int length)
Returns the size of the (binary) serialized
int array in bytes. |
int |
getBinarySize(long value)
Returns the size of the (binary) serialized
long in bytes. |
int |
getBinarySize(long[] array)
Returns the size of the (binary) serialized
long array in bytes. |
int |
getBinarySize(long[] array,
int index,
int length)
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 value)
Returns the size of the (binary) serialized
short in bytes. |
int |
getBinarySize(short[] array)
Returns the size of the (binary) serialized
short array in bytes. |
int |
getBinarySize(short[] array,
int index,
int length)
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. |
int |
getBinarySize(java.lang.String[] array)
Returns the size of the (binary) serialized
String array in bytes. |
protected static <T> java.lang.reflect.Constructor<T> |
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. |
int |
objectToBuffer(BinaryInput stream,
java.nio.ByteBuffer buffer,
int copySize)
Reads one object from the input stream into a buffer (including the header), no deserialization is performed.
|
java.math.BigInteger |
readBigInteger(BinaryInput input)
Returns a
BigInteger value read from the specified input. |
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. |
<E extends java.lang.Enum<?>> |
readEnum(BinaryInput input,
java.lang.Class<E> enumClass)
Returns an
Enum 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. |
<E> E |
readFromFile(java.lang.Class<? extends E> expectedClass,
boolean bufferDirect,
java.io.File inputFile)
Reads an instance from the
input using this serializator. |
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. |
<E> E |
readObject(BinaryInput input,
java.lang.Class<E> expectedClass)
Reads an instance from the
input using this serializator. |
protected abstract <E> E |
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. |
java.lang.String[] |
readStringArray(BinaryInput input)
Returns a
String array read from the specified input. |
int |
skipObject(BinaryInput stream,
boolean skipDeleted)
Skip the object at the current position of the stream.
|
int |
write(BinaryOutput output,
java.math.BigInteger value)
Writes a
BigInteger value to the specified output. |
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,
java.lang.Enum<?> enumInstance)
Writes an
Enum 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. |
int |
write(BinaryOutput output,
java.lang.String[] array)
Writes a
String array to the specified output. |
BufferOutputStream |
write(java.lang.Object object,
boolean bufferDirect)
Writes
object to a new buffer output stream. |
void |
writeToFile(java.lang.Object object,
boolean bufferDirect,
java.io.File outputFile)
Writes
object to a given file. |
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 writtenjava.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 writtenjava.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 writtenjava.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 writtenjava.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 writtenjava.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 writtenjava.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 writtenjava.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 writtenjava.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, java.math.BigInteger value) throws java.io.IOException
BigInteger
value to the specified output.output
- the output buffer to write the value intovalue
- the BigInteger
value to be writtenjava.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 writejava.io.IOException
- if there was an I/O errorjava.lang.NullPointerException
- if the specified array is nulljava.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 writejava.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 writejava.io.IOException
- if there was an I/O errorjava.lang.NullPointerException
- if the specified array is nulljava.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 writejava.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 writejava.io.IOException
- if there was an I/O errorjava.lang.NullPointerException
- if the specified array is nulljava.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 writejava.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 writejava.io.IOException
- if there was an I/O errorjava.lang.NullPointerException
- if the specified array is nulljava.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 writejava.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 writejava.io.IOException
- if there was an I/O errorjava.lang.NullPointerException
- if the specified array is nulljava.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 writejava.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 writejava.io.IOException
- if there was an I/O errorjava.lang.NullPointerException
- if the specified array is nulljava.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 writejava.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 writejava.io.IOException
- if there was an I/O errorjava.lang.NullPointerException
- if the specified array is nulljava.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 writejava.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 writejava.io.IOException
- if there was an I/O errorjava.lang.NullPointerException
- if the specified array is nulljava.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 writejava.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 writtenjava.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, java.lang.String[] array) throws java.io.IOException
String
array to the specified output.output
- the buffer to write the string array intoarray
- the String
array to be writtenjava.io.IOException
- if there was an I/O errorpublic int write(BinaryOutput output, java.lang.Enum<?> enumInstance) throws java.io.IOException
Enum
to the specified output.output
- the buffer to write the enum intoenumInstance
- the enum to be writtenjava.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 writejava.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 flushChannelpublic final void writeToFile(java.lang.Object object, boolean bufferDirect, java.io.File outputFile) throws java.io.IOException
object
to a given file.
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)outputFile
- the file to output the data tojava.io.IOException
- if there was an error writing the datapublic final <E> E readFromFile(java.lang.Class<? extends E> expectedClass, boolean bufferDirect, java.io.File inputFile) throws java.io.IOException
input
using this serializator.E
- the class that is expected to be in the inputexpectedClass
- the class that is expected to be in the inputbufferDirect
- the type of buffer to use (direct or array-backed)inputFile
- the file 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 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 methodoutput
- the buffer to write the object toobject
- the object to writejava.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 fromboolean
value read from the inputjava.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 frombyte
value read from the inputjava.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 fromshort
value read from the inputjava.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 fromchar
value read from the inputjava.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 fromint
value read from the inputjava.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 fromlong
value read from the inputjava.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 fromfloat
value read from the inputjava.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 fromdouble
value read from the inputjava.io.IOException
- if there was an I/O errorpublic java.math.BigInteger readBigInteger(BinaryInput input) throws java.io.IOException
BigInteger
value read from the specified input.input
- the input buffer to read the value fromBigInteger
value read from the inputjava.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 fromboolean
array read from the inputjava.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 frombyte
array read from the inputjava.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 fromshort
array read from the inputjava.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 fromchar
array read from the inputjava.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 fromint
array read from the inputjava.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 fromlong
array read from the inputjava.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 fromfloat
array read from the inputjava.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 fromdouble
array read from the inputjava.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 fromString
read from the inputjava.io.IOException
- if there was an I/O errorpublic java.lang.String[] readStringArray(BinaryInput input) throws java.io.IOException
String
array read from the specified input.input
- the buffer to read the array fromString
array read from the inputjava.io.IOException
- if there was an I/O errorpublic final <E extends java.lang.Enum<?>> E readEnum(BinaryInput input, java.lang.Class<E> enumClass) throws java.io.IOException
Enum
read from the specified input.E
- the enum class that is expected to be in the inputinput
- the buffer to read the enum fromenumClass
- the enum class that is expected to be in the inputEnum
read from the inputjava.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 inputjava.io.IOException
- if there was an I/O errorjava.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 themE
- 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 inputjava.io.IOException
- if there was an I/O errorjava.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 readjava.io.IOException
- if there was an I/O errorjava.lang.IllegalArgumentException
- if the constructor or the factory method has a wrong prototypepublic int getBinarySize(boolean value)
boolean
in bytes.
The exact size including all overhead is returned.value
- the value to get the size forpublic int getBinarySize(boolean[] array)
boolean
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forpublic int getBinarySize(boolean[] array, int index, int length)
boolean
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forindex
- the start index in the arraylength
- the number of array items to writepublic int getBinarySize(byte value)
byte
in bytes.
The exact size including all overhead is returned.value
- the value to get the size forpublic int getBinarySize(byte[] array)
byte
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forpublic int getBinarySize(byte[] array, int index, int length)
byte
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forindex
- the start index in the arraylength
- the number of array items to writepublic int getBinarySize(short value)
short
in bytes.
The exact size including all overhead is returned.value
- the value to get the size forpublic int getBinarySize(short[] array)
short
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forpublic int getBinarySize(short[] array, int index, int length)
short
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forindex
- the start index in the arraylength
- the number of array items to writepublic int getBinarySize(char value)
char
in bytes.
The exact size including all overhead is returned.value
- the value to get the size forpublic int getBinarySize(char[] array)
char
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forpublic int getBinarySize(char[] array, int index, int length)
char
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forindex
- the start index in the arraylength
- the number of array items to writepublic int getBinarySize(int value)
int
in bytes.
The exact size including all overhead is returned.value
- the value to get the size forpublic int getBinarySize(int[] array)
int
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forpublic int getBinarySize(int[] array, int index, int length)
int
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forindex
- the start index in the arraylength
- the number of array items to writepublic int getBinarySize(long value)
long
in bytes.
The exact size including all overhead is returned.value
- the value to get the size forpublic int getBinarySize(long[] array)
long
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forpublic int getBinarySize(long[] array, int index, int length)
long
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forindex
- the start index in the arraylength
- the number of array items to writepublic int getBinarySize(float value)
float
in bytes.
The exact size including all overhead is returned.value
- the value to get the size forpublic int getBinarySize(float[] array)
float
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forpublic int getBinarySize(float[] array, int index, int length)
float
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forindex
- the start index in the arraylength
- the number of array items to writepublic int getBinarySize(double value)
double
in bytes.
The exact size including all overhead is returned.value
- the value to get the size forpublic int getBinarySize(double[] array)
double
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forpublic int getBinarySize(double[] array, int index, int length)
double
array in bytes.
The exact size including all overhead is returned.array
- the array to get the size forindex
- the start index in the arraylength
- the number of array items to writepublic int getBinarySize(java.math.BigInteger value)
BigInteger
in bytes. The exact size including all
overhead is returned.value
- the value to get the size forpublic int getBinarySize(java.lang.String string)
String
in bytes.
The exact size including all overhead is returned.string
- the string to get the size forString
public int getBinarySize(java.lang.String[] array)
String
array in bytes.
The exact size including all overhead is returned.array
- the string array to get the size forString
arraypublic int getBinarySize(java.lang.Enum<?> enumInstance)
Enum
in bytes.
The exact size including all overhead is returned.enumInstance
- the enum to get the size forprotected int readObjectSize(BinaryInput input) throws java.io.IOException
input
- the buffer from which to read the object sizejava.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 int objectToBuffer(BinaryInput stream, java.nio.ByteBuffer buffer, int copySize) throws java.io.IOException
stream
- the stream to read the object frombuffer
- the buffer into which an object is readcopySize
- the maximal number of bytes read by a bulk read operation (i.e. the input stream buffer size)java.io.IOException
- if there was a problem reading the stream or the given buffer is too small to hold the object datapublic 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 forobject
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 forobject
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 constructobjectClass
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 constructobjectClass
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 versionjava.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