org.deegree.services.wpvs.io.serializer
Class ObjectSerializer<T extends PositionableModel>

java.lang.Object
  extended by org.deegree.services.wpvs.io.serializer.ObjectSerializer<T>
Type Parameters:
T -
Direct Known Subclasses:
BillBoardSerializer, PrototypeSerializer, WROSerializer

public abstract class ObjectSerializer<T extends PositionableModel>
extends Object

The ObjectSerializer class TODO add class documentation here.

Version:
$Revision: 30127 $, $Date: 2011-03-22 11:11:12 +0100 (Tue, 22 Mar 2011) $
Author:
Rutger Bezema, last edited by: $Author: aschmitz $

Constructor Summary
ObjectSerializer()
           
 
Method Summary
 ByteBuffer allocateByteBuffer(FileChannel channel)
          Allocates a byte buffer to hold the total object.
 T deserializeDataObject(byte[] buffer)
          Deserialize an object from the given byte array.
 int getHeaderSize(String uuid)
           
abstract  T read(ByteBuffer buffer)
          Create a PositionableModel by reading it from the buffer.
 String readID(ByteBuffer buffer)
          Read the id of this object and reset the position to it's start position.
 int readObjectSize(ByteBuffer buffer)
          Read the size of the serialized object and reset the position to it's start position.
static String readString(ByteBuffer buffer)
          Reads a string from the buffer, using UTF-8.
 long readTime(ByteBuffer buffer)
          Read the creation time of this object and reset the position to it's start position.
abstract  int serializedObjectSize(DataObjectInfo<T> object)
          Returns the size of the object after serialization, without the header information, just the fields.
 byte[] serializeObject(DataObjectInfo<T> doi)
          Serializes an object using the standard serialization mechanism, ObjectOutputStream
 int sizeOfSerializedObject(DataObjectInfo<T> object)
          Returns the size of the object after serialization, with the header information and the fields.
static int sizeOfString(String string)
          Return the size of the given string in UTF-8 plus the length index
 void skipHeader(ByteBuffer buffer)
          Skips the header.
abstract  void write(ByteBuffer buffer, DataObjectInfo<T> object)
          Write the given PositionableModel to the buffer.
 void writeHeader(ByteBuffer buffer, DataObjectInfo<T> object)
          Writes the default header, consisting of the totalSize, id and the currentTimeMillis().
static void writeString(ByteBuffer buffer, String string)
          Writes a string to the buffer, by using UTF-8.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectSerializer

public ObjectSerializer()
Method Detail

write

public abstract void write(ByteBuffer buffer,
                           DataObjectInfo<T> object)
Write the given PositionableModel to the buffer.

Parameters:
buffer -
object -

read

public abstract T read(ByteBuffer buffer)
Create a PositionableModel by reading it from the buffer.

Parameters:
buffer -
Returns:
the instantiated PositionableModel

serializedObjectSize

public abstract int serializedObjectSize(DataObjectInfo<T> object)
Returns the size of the object after serialization, without the header information, just the fields.

Parameters:
object - to get the size from
Returns:
the size of the object after serialization, without the header information.

writeHeader

public void writeHeader(ByteBuffer buffer,
                        DataObjectInfo<T> object)
Writes the default header, consisting of the totalSize, id and the currentTimeMillis().

Parameters:
buffer -
object - to write the header from.

skipHeader

public void skipHeader(ByteBuffer buffer)
Skips the header.

Parameters:
buffer -

allocateByteBuffer

public ByteBuffer allocateByteBuffer(FileChannel channel)
                              throws IOException
Allocates a byte buffer to hold the total object.

Parameters:
channel -
Returns:
an allocated bytebuffer large enough to deserialize the next object.
Throws:
IOException

sizeOfSerializedObject

public int sizeOfSerializedObject(DataObjectInfo<T> object)
Returns the size of the object after serialization, with the header information and the fields.

Parameters:
object - to get the size from
Returns:
the size of the object after serialization, with the header information.

readID

public String readID(ByteBuffer buffer)
Read the id of this object and reset the position to it's start position.

Parameters:
buffer - to read from
Returns:
the id of the object or 0 if the id could not be read.

readTime

public long readTime(ByteBuffer buffer)
Read the creation time of this object and reset the position to it's start position.

Parameters:
buffer - to read from
Returns:
the creation time of the object or 0 if the time could not be read.

getHeaderSize

public int getHeaderSize(String uuid)
Parameters:
uuid -
Returns:
the size of the header starting from the position of the object.

writeString

public static void writeString(ByteBuffer buffer,
                               String string)
Writes a string to the buffer, by using UTF-8.

Parameters:
buffer -
string -

readString

public static String readString(ByteBuffer buffer)
Reads a string from the buffer, using UTF-8.

Parameters:
buffer -
Returns:
string

sizeOfString

public static int sizeOfString(String string)
Return the size of the given string in UTF-8 plus the length index

Parameters:
string -
Returns:
the size of the given string in UTF-8, or in the default platform encoding.

readObjectSize

public int readObjectSize(ByteBuffer buffer)
Read the size of the serialized object and reset the position to it's start position.

Parameters:
buffer - to read from
Returns:
the size of the object.

serializeObject

public byte[] serializeObject(DataObjectInfo<T> doi)
Serializes an object using the standard serialization mechanism, ObjectOutputStream

Parameters:
doi - to be serialized with the ObjectOutputStream
Returns:
the byte array containing the serialized object.

deserializeDataObject

public T deserializeDataObject(byte[] buffer)
Deserialize an object from the given byte array.

Parameters:
buffer - containing bytes to deserialize.
Returns:
the deserialized object of type T.


Copyright © 2011. All Rights Reserved.