messif.objects.nio
Class BinarySerializator

java.lang.Object
  extended by messif.objects.nio.BinarySerializator
Direct Known Subclasses:
MultiClassSerializator, SingleClassSerializator

public abstract class BinarySerializator
extends java.lang.Object

This class provides a framework for binary serialization of objects. It operates on any BinaryInput/BinaryOutput.

See Also:
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 booleanarray in bytes.
 int getBinarySize(byte[] array)
          Returns the size of the (binary) serialized bytearray in bytes.
 int getBinarySize(double[] array)
          Returns the size of the (binary) serialized doublearray in bytes.
 int getBinarySize(float[] array)
          Returns the size of the (binary) serialized floatarray in bytes.
 int getBinarySize(char[] array)
          Returns the size of the (binary) serialized chararray in bytes.
 int getBinarySize(int[] array)
          Returns the size of the (binary) serialized intarray in bytes.
 int getBinarySize(long[] array)
          Returns the size of the (binary) serialized longarray 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 shortarray in bytes.
 int getBinarySize(java.lang.String string)
          Returns the size of the (binary) serialized String 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.
 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.
<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.
 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

log

protected static final java.util.logging.Logger log
Logger for serializators

Constructor Detail

BinarySerializator

public BinarySerializator()
Method Detail

write

public int write(BinaryOutput output,
                 boolean value)
          throws java.io.IOException
Writes a boolean value to the specified output.

Parameters:
output - the output buffer to write the value into
value - the boolean value to be written
Returns:
the number of bytes written
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 byte value)
          throws java.io.IOException
Writes a byte value to the specified output.

Parameters:
output - the output buffer to write the value into
value - the byte value to be written
Returns:
the number of bytes written
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 short value)
          throws java.io.IOException
Writes a short value to the specified output.

Parameters:
output - the output buffer to write the value into
value - the short value to be written
Returns:
the number of bytes written
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 char value)
          throws java.io.IOException
Writes a char value to the specified output.

Parameters:
output - the output buffer to write the value into
value - the char value to be written
Returns:
the number of bytes written
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 int value)
          throws java.io.IOException
Writes a int value to the specified output.

Parameters:
output - the output buffer to write the value into
value - the int value to be written
Returns:
the number of bytes written
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 long value)
          throws java.io.IOException
Writes a long value to the specified output.

Parameters:
output - the output buffer to write the value into
value - the long value to be written
Returns:
the number of bytes written
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 float value)
          throws java.io.IOException
Writes a float value to the specified output.

Parameters:
output - the output buffer to write the value into
value - the float value to be written
Returns:
the number of bytes written
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 double value)
          throws java.io.IOException
Writes a double value to the specified output.

Parameters:
output - the output buffer to write the value into
value - the double value to be written
Returns:
the number of bytes written
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 boolean[] array,
                 int index,
                 int length)
          throws java.io.IOException,
                 java.lang.NullPointerException,
                 java.lang.IndexOutOfBoundsException
Writes a boolean array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the boolean array to write
index - the start index in the boolean array
length - the number of array items to write
Returns:
the number of bytes written to the output
Throws:
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 array

write

public int write(BinaryOutput output,
                 boolean[] array)
          throws java.io.IOException
Writes a boolean array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the boolean array to write
Returns:
the number of bytes written to the output
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 byte[] array,
                 int index,
                 int length)
          throws java.io.IOException,
                 java.lang.NullPointerException,
                 java.lang.IndexOutOfBoundsException
Writes a byte array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the byte array to write
index - the start index in the byte array
length - the number of array items to write
Returns:
the number of bytes written to the output
Throws:
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 array

write

public int write(BinaryOutput output,
                 byte[] array)
          throws java.io.IOException
Writes a byte array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the byte array to write
Returns:
the number of bytes written to the output
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 short[] array,
                 int index,
                 int length)
          throws java.io.IOException,
                 java.lang.NullPointerException,
                 java.lang.IndexOutOfBoundsException
Writes a short array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the short array to write
index - the start index in the short array
length - the number of array items to write
Returns:
the number of bytes written to the output
Throws:
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 array

write

public int write(BinaryOutput output,
                 short[] array)
          throws java.io.IOException
Writes a short array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the short array to write
Returns:
the number of bytes written to the output
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 char[] array,
                 int index,
                 int length)
          throws java.io.IOException,
                 java.lang.NullPointerException,
                 java.lang.IndexOutOfBoundsException
Writes a char array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the char array to write
index - the start index in the char array
length - the number of array items to write
Returns:
the number of bytes written to the output
Throws:
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 array

write

public int write(BinaryOutput output,
                 char[] array)
          throws java.io.IOException
Writes a char array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the char array to write
Returns:
the number of bytes written to the output
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 int[] array,
                 int index,
                 int length)
          throws java.io.IOException,
                 java.lang.NullPointerException,
                 java.lang.IndexOutOfBoundsException
Writes a int array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the int array to write
index - the start index in the int array
length - the number of array items to write
Returns:
the number of bytes written to the output
Throws:
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 array

write

public int write(BinaryOutput output,
                 int[] array)
          throws java.io.IOException
Writes a int array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the int array to write
Returns:
the number of bytes written to the output
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 long[] array,
                 int index,
                 int length)
          throws java.io.IOException,
                 java.lang.NullPointerException,
                 java.lang.IndexOutOfBoundsException
Writes a long array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the long array to write
index - the start index in the long array
length - the number of array items to write
Returns:
the number of bytes written to the output
Throws:
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 array

write

public int write(BinaryOutput output,
                 long[] array)
          throws java.io.IOException
Writes a long array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the long array to write
Returns:
the number of bytes written to the output
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 float[] array,
                 int index,
                 int length)
          throws java.io.IOException,
                 java.lang.NullPointerException,
                 java.lang.IndexOutOfBoundsException
Writes a float array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the float array to write
index - the start index in the float array
length - the number of array items to write
Returns:
the number of bytes written to the output
Throws:
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 array

write

public int write(BinaryOutput output,
                 float[] array)
          throws java.io.IOException
Writes a float array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the float array to write
Returns:
the number of bytes written to the output
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 double[] array,
                 int index,
                 int length)
          throws java.io.IOException,
                 java.lang.NullPointerException,
                 java.lang.IndexOutOfBoundsException
Writes a double array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the double array to write
index - the start index in the double array
length - the number of array items to write
Returns:
the number of bytes written to the output
Throws:
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 array

write

public int write(BinaryOutput output,
                 double[] array)
          throws java.io.IOException
Writes a double array to the specified output.

Parameters:
output - the output buffer to write the array into
array - the double array to write
Returns:
the number of bytes written to the output
Throws:
java.io.IOException - if there was an I/O error

write

public int write(BinaryOutput output,
                 java.lang.String string)
          throws java.io.IOException
Writes a String to the specified output.

Parameters:
output - the buffer to write the string into
string - the String to be written
Returns:
the number of bytes written
Throws:
java.io.IOException - if there was an I/O error

write

public final int write(BinaryOutput output,
                       java.lang.Object object)
                throws java.io.IOException
Writes object to the provided output buffer. If the object implements BinarySerializable interface, it is binary-serialized. Otherwise, a standard Java serialization is used.

Parameters:
output - the buffer to write the object to
object - the object to write
Returns:
the number of bytes actually written
Throws:
java.io.IOException - if there was an error using flushChannel

write

public final BufferOutputStream write(java.lang.Object object,
                                      boolean bufferDirect)
                               throws java.io.IOException
Writes object to a new buffer output stream. If the object implements BinarySerializable interface, it is binary-serialized. Otherwise, a standard Java serialization is used.

Parameters:
object - the object to write
bufferDirect - the type of buffer to use (direct or array-backed)
Returns:
the create buffer that contains the serialized object
Throws:
java.io.IOException - if there was an error using flushChannel

write

protected abstract int write(BinaryOutput output,
                             BinarySerializable object)
                      throws java.io.IOException
Writes object to this output buffer using binary serialization. The following rules must hold:

Parameters:
output - the buffer to write the object to
object - the object to write
Returns:
the number of bytes actually written
Throws:
java.io.IOException - if there was an error using flushChannel

readBoolean

public boolean readBoolean(BinaryInput input)
                    throws java.io.IOException
Returns a boolean value read from the specified input.

Parameters:
input - the input buffer to read the value from
Returns:
a boolean value read from the input
Throws:
java.io.IOException - if there was an I/O error

readByte

public byte readByte(BinaryInput input)
              throws java.io.IOException
Returns a byte value read from the specified input.

Parameters:
input - the input buffer to read the value from
Returns:
a byte value read from the input
Throws:
java.io.IOException - if there was an I/O error

readShort

public short readShort(BinaryInput input)
                throws java.io.IOException
Returns a short value read from the specified input.

Parameters:
input - the input buffer to read the value from
Returns:
a short value read from the input
Throws:
java.io.IOException - if there was an I/O error

readChar

public char readChar(BinaryInput input)
              throws java.io.IOException
Returns a char value read from the specified input.

Parameters:
input - the input buffer to read the value from
Returns:
a char value read from the input
Throws:
java.io.IOException - if there was an I/O error

readInt

public int readInt(BinaryInput input)
            throws java.io.IOException
Returns a int value read from the specified input.

Parameters:
input - the input buffer to read the value from
Returns:
a int value read from the input
Throws:
java.io.IOException - if there was an I/O error

readLong

public long readLong(BinaryInput input)
              throws java.io.IOException
Returns a long value read from the specified input.

Parameters:
input - the input buffer to read the value from
Returns:
a long value read from the input
Throws:
java.io.IOException - if there was an I/O error

readFloat

public float readFloat(BinaryInput input)
                throws java.io.IOException
Returns a float value read from the specified input.

Parameters:
input - the input buffer to read the value from
Returns:
a float value read from the input
Throws:
java.io.IOException - if there was an I/O error

readDouble

public double readDouble(BinaryInput input)
                  throws java.io.IOException
Returns a double value read from the specified input.

Parameters:
input - the input buffer to read the value from
Returns:
a double value read from the input
Throws:
java.io.IOException - if there was an I/O error

readBooleanArray

public boolean[] readBooleanArray(BinaryInput input)
                           throws java.io.IOException
Returns a boolean array read from the specified input.

Parameters:
input - the buffer to read the array from
Returns:
a boolean array read from the input
Throws:
java.io.IOException - if there was an I/O error

readByteArray

public byte[] readByteArray(BinaryInput input)
                     throws java.io.IOException
Returns a byte array read from the specified input.

Parameters:
input - the buffer to read the array from
Returns:
a byte array read from the input
Throws:
java.io.IOException - if there was an I/O error

readShortArray

public short[] readShortArray(BinaryInput input)
                       throws java.io.IOException
Returns a short array read from the specified input.

Parameters:
input - the buffer to read the array from
Returns:
a short array read from the input
Throws:
java.io.IOException - if there was an I/O error

readCharArray

public char[] readCharArray(BinaryInput input)
                     throws java.io.IOException
Returns a char array read from the specified input.

Parameters:
input - the buffer to read the array from
Returns:
a char array read from the input
Throws:
java.io.IOException - if there was an I/O error

readIntArray

public int[] readIntArray(BinaryInput input)
                   throws java.io.IOException
Returns a int array read from the specified input.

Parameters:
input - the buffer to read the array from
Returns:
a int array read from the input
Throws:
java.io.IOException - if there was an I/O error

readLongArray

public long[] readLongArray(BinaryInput input)
                     throws java.io.IOException
Returns a long array read from the specified input.

Parameters:
input - the buffer to read the array from
Returns:
a long array read from the input
Throws:
java.io.IOException - if there was an I/O error

readFloatArray

public float[] readFloatArray(BinaryInput input)
                       throws java.io.IOException
Returns a float array read from the specified input.

Parameters:
input - the buffer to read the array from
Returns:
a float array read from the input
Throws:
java.io.IOException - if there was an I/O error

readDoubleArray

public double[] readDoubleArray(BinaryInput input)
                         throws java.io.IOException
Returns a double array read from the specified input.

Parameters:
input - the buffer to read the array from
Returns:
a double array read from the input
Throws:
java.io.IOException - if there was an I/O error

readString

public java.lang.String readString(BinaryInput input)
                            throws java.io.IOException
Returns a String read from the specified input.

Parameters:
input - the buffer to read the string from
Returns:
a String read from the input
Throws:
java.io.IOException - if there was an I/O error

readObject

public final <E> E readObject(BinaryInput input,
                              java.lang.Class<E> expectedClass)
                   throws java.io.IOException,
                          java.lang.IllegalArgumentException
Reads an instance from the input using this serializator.

Type Parameters:
E - the class that is expected to be in the input
Parameters:
input - the buffer to read the instance from
expectedClass - the class that is expected to be in the input
Returns:
an instance of the deserialized object
Throws:
java.io.IOException - if there was an I/O error
java.lang.IllegalArgumentException - if the constructor or the factory method has a wrong prototype

readObjectImpl

protected abstract <E> E readObjectImpl(BinaryInput input,
                                        java.lang.Class<E> expectedClass)
                             throws java.io.IOException,
                                    java.lang.IllegalArgumentException
Reads an instance using the proper constructor/factory method as specified by this serializator. The following rules must hold:

Type Parameters:
E - the class that is expected to be in the input
Parameters:
input - the buffer to read the instance from
expectedClass - the class that is expected to be in the input
Returns:
an instance of the deserialized object
Throws:
java.io.IOException - if there was an I/O error
java.lang.IllegalArgumentException - if the constructor or the factory method has a wrong prototype

readObject

protected 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
Reads an instance created by constructor or factoryMethod from the input buffer. If both the constructor and the factory method are null, standard Java deserialization is used.

Parameters:
input - the buffer to read the instance from
serializator - the serializator used to write objects
constructor - the constructor of the object class to read
factoryMethod - the factory method of the object class to read
Returns:
an instance of the deserialized object
Throws:
java.io.IOException - if there was an I/O error
java.lang.IllegalArgumentException - if the constructor or the factory method has a wrong prototype

getBinarySize

public int getBinarySize(boolean[] array)
Returns the size of the (binary) serialized booleanarray in bytes. The exact size including all overhead is returned.

Parameters:
array - the array to get the size for
Returns:
the size of the binary-serialized array

getBinarySize

public int getBinarySize(byte[] array)
Returns the size of the (binary) serialized bytearray in bytes. The exact size including all overhead is returned.

Parameters:
array - the array to get the size for
Returns:
the size of the binary-serialized array

getBinarySize

public int getBinarySize(short[] array)
Returns the size of the (binary) serialized shortarray in bytes. The exact size including all overhead is returned.

Parameters:
array - the array to get the size for
Returns:
the size of the binary-serialized array

getBinarySize

public int getBinarySize(char[] array)
Returns the size of the (binary) serialized chararray in bytes. The exact size including all overhead is returned.

Parameters:
array - the array to get the size for
Returns:
the size of the binary-serialized array

getBinarySize

public int getBinarySize(int[] array)
Returns the size of the (binary) serialized intarray in bytes. The exact size including all overhead is returned.

Parameters:
array - the array to get the size for
Returns:
the size of the binary-serialized array

getBinarySize

public int getBinarySize(long[] array)
Returns the size of the (binary) serialized longarray in bytes. The exact size including all overhead is returned.

Parameters:
array - the array to get the size for
Returns:
the size of the binary-serialized array

getBinarySize

public int getBinarySize(float[] array)
Returns the size of the (binary) serialized floatarray in bytes. The exact size including all overhead is returned.

Parameters:
array - the array to get the size for
Returns:
the size of the binary-serialized array

getBinarySize

public int getBinarySize(double[] array)
Returns the size of the (binary) serialized doublearray in bytes. The exact size including all overhead is returned.

Parameters:
array - the array to get the size for
Returns:
the size of the binary-serialized array

getBinarySize

public int getBinarySize(java.lang.String string)
Returns the size of the (binary) serialized String in bytes. The exact size including all overhead is returned.

Parameters:
string - the string to get the size for
Returns:
the size of the binary-serialized String

readObjectSize

protected int readObjectSize(BinaryInput input)
                      throws java.io.IOException
Read the size of the object at the current position of the buffer. This method will skip the deleted objects, i.e. the size stored in the stream is negative. Position is advanced to the beginning of the object's data.

Parameters:
input - the buffer from which to read the object size
Returns:
the size of the object
Throws:
java.io.IOException - if there was an error reading from the input buffer

skipObject

public int skipObject(BinaryInput stream,
                      boolean skipDeleted)
               throws java.io.IOException
Skip the object at the current position of the stream.

Parameters:
stream - the stream in which to skip an object
skipDeleted - if true the deleted object are silently skipped (their sizes are not reported)
Returns:
the skipped object's size in bytes - it is negative if the object was deleted
Throws:
java.io.IOException - if there was an error reading from the input stream

getBinarySize

public final int getBinarySize(java.lang.Object object)
                        throws java.lang.IllegalArgumentException
Returns the size of the (binary) serialized 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.

Parameters:
object - the object to get the size for
Returns:
the size of the binary-serialized object
Throws:
java.lang.IllegalArgumentException - if there was an error using Java standard serialization on the object

getBinarySize

protected abstract int getBinarySize(BinarySerializable object)
                              throws java.lang.IllegalArgumentException
Returns the size of the binary-serialized object in bytes.

Parameters:
object - the object to get the size for
Returns:
the size of the binary-serialized object
Throws:
java.lang.IllegalArgumentException - if there was an error using Java standard serialization on the object

getNativeSerializableConstructor

protected static <T> java.lang.reflect.Constructor<T> getNativeSerializableConstructor(java.lang.Class<T> objectClass)
Returns a native-serializable constructor for objectClass. The constructor should have the following prototype:
      ClassConstructor(BinaryInput input, BinarySerializator serializator) throws IOException
 

Type Parameters:
T - the object class to construct
Parameters:
objectClass - the object class to construct
Returns:
a constructor for objectClass or null if there is no native-serializable constructor

getNativeSerializableFactoryMethod

protected static java.lang.reflect.Method getNativeSerializableFactoryMethod(java.lang.Class<?> objectClass)
Returns a native-serializable factory method for objectClass. The factory method should have the following prototype:
      ObjectClass binaryDeserialize(BinaryInput input, BinarySerializator serializator) throws IOException
 

Parameters:
objectClass - the object class to construct
Returns:
a factory method for objectClass or null if there is no native-serializable factory method

getSerialVersionUID

protected static long getSerialVersionUID(java.lang.Class<?> classToCheck)
                                   throws java.lang.NoSuchFieldException
Returns the value of the serialVersionUID field for the specified class.

Parameters:
classToCheck - the class for which to look-up the serial version
Returns:
the serial version of the specified class
Throws:
java.lang.NoSuchFieldException - if the class does not have serial version

getSerialVersionUIDHash

protected static int getSerialVersionUIDHash(java.lang.Class<?> classToCheck)
Returns the hash code for value of the serialVersionUID field of the specified class.

Parameters:
classToCheck - the class for which to look-up the serial version
Returns:
the serial version of the specified class