org.deegree.services.wpvs.io.serializer
Class ObjectSerializer<T extends org.deegree.commons.index.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 org.deegree.commons.index.PositionableModel>
extends java.lang.Object

The ObjectSerializer class TODO add class documentation here.

Version:
$Revision: 22959 $, $Date: 2010-03-10 13:04:37 +0100 (Mi, 10. Mär 2010) $
Author:
Rutger Bezema, last edited by: $Author: rbezema $

Constructor Summary
ObjectSerializer()
           
 
Method Summary
 java.nio.ByteBuffer allocateByteBuffer(java.nio.channels.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(java.lang.String uuid)
           
abstract  T read(java.nio.ByteBuffer buffer)
          Create a PositionableModel by reading it from the buffer.
 java.lang.String readID(java.nio.ByteBuffer buffer)
          Read the id of this object and reset the position to it's start position.
 int readObjectSize(java.nio.ByteBuffer buffer)
          Read the size of the serialized object and reset the position to it's start position.
static java.lang.String readString(java.nio.ByteBuffer buffer)
          Reads a string from the buffer, using UTF-8.
 long readTime(java.nio.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(java.lang.String string)
          Return the size of the given string in UTF-8 plus the length index
 void skipHeader(java.nio.ByteBuffer buffer)
          Skips the header.
abstract  void write(java.nio.ByteBuffer buffer, DataObjectInfo<T> object)
          Write the given PositionableModel to the buffer.
 void writeHeader(java.nio.ByteBuffer buffer, DataObjectInfo<T> object)
          Writes the default header, consisting of the totalSize, id and the currentTimeMillis().
static void writeString(java.nio.ByteBuffer buffer, java.lang.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(java.nio.ByteBuffer buffer,
                           DataObjectInfo<T> object)
Write the given PositionableModel to the buffer.

Parameters:
buffer -
object -

read

public abstract T read(java.nio.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(java.nio.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(java.nio.ByteBuffer buffer)
Skips the header.

Parameters:
buffer -

allocateByteBuffer

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

Parameters:
channel -
Returns:
an allocated bytebuffer large enough to deserialize the next object.
Throws:
java.io.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 java.lang.String readID(java.nio.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(java.nio.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(java.lang.String uuid)
Parameters:
uuid -
Returns:
the size of the header starting from the position of the object.

writeString

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

Parameters:
buffer -
string -

readString

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

Parameters:
buffer -
Returns:
string

sizeOfString

public static int sizeOfString(java.lang.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(java.nio.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.