com.joanju
Class DataXferStream

java.lang.Object
  extended by com.joanju.DataXferStream

public class DataXferStream
extends java.lang.Object

Serialize objects to a blob optimized for random access. Objects of this class must only be used within a single thread.

Several hours of searching the internet turned up many different tools for serialization, but none of them (that I could find) were designed with direct, fast random access as the primary consideration.

This and Xferable are designed such that it is self-describing, and if the output class 'schemas' are used correctly, there should never be a reason for the addition of new data fields added to the output to break any code using 'old' versions of the schema. Each byte offset is written with a field-reference-name, and the schema is written to every blob.


Constructor Summary
DataXferStream()
           
 
Method Summary
 void addSchemaFor(Xferable x)
          May be used for building an xfer blob just for schema purposes.
 void buildIndexes()
          Must be called after all objects have been stored.
 java.io.ByteArrayOutputStream getBytes()
          Once buildIndex() has been called, then use this to get the blob.
 int getIndexOffset()
           
 int getOffsetOf(java.lang.Object o)
          Get the offset of an object that's already been stored.
 int getSchemaMapOffset()
           
 void schemaBool(java.lang.String fieldName)
           
 void schemaInt(java.lang.String fieldName)
           
 void schemaRef(java.lang.String fieldName)
           
 int size()
          Get the size in bytes.
 int store(java.lang.Object o)
          Store an object and any object hierarchy that comes with it.
 void writeBool(boolean b)
          Called by Xferable.writeXferBytes() for boolean fields.
 void writeInt(int i)
          Called by Xferable.writeXferBytes() for int fields.
 void writeRef(java.lang.Object o)
          Called by Xferable.writeXferBytes().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataXferStream

public DataXferStream()
Method Detail

addSchemaFor

public void addSchemaFor(Xferable x)
May be used for building an xfer blob just for schema purposes.


buildIndexes

public void buildIndexes()
                  throws java.io.IOException
Must be called after all objects have been stored.

Throws:
java.io.IOException

getBytes

public java.io.ByteArrayOutputStream getBytes()
Once buildIndex() has been called, then use this to get the blob.


getIndexOffset

public int getIndexOffset()

getSchemaMapOffset

public int getSchemaMapOffset()

getOffsetOf

public int getOffsetOf(java.lang.Object o)
                throws java.io.IOException
Get the offset of an object that's already been stored. Returns -1 if the object is not stored.

Throws:
java.io.IOException

schemaBool

public void schemaBool(java.lang.String fieldName)
                throws java.io.IOException
Throws:
java.io.IOException

schemaInt

public void schemaInt(java.lang.String fieldName)
               throws java.io.IOException
Throws:
java.io.IOException

schemaRef

public void schemaRef(java.lang.String fieldName)
               throws java.io.IOException
Throws:
java.io.IOException

size

public int size()
Get the size in bytes.


store

public int store(java.lang.Object o)
          throws java.io.IOException
Store an object and any object hierarchy that comes with it. The process that creates a DataXferStream would typically call this next, and this might be called multiple times, depending on how many object hierarchies are to be stored. After all object hierarchies have been stored, then buildIndex() should be called before getting the byte array. This is NOT TO BE CALLED FROM Xferable.writeXferBytes().

Returns:
The offset of the stored object record.
Throws:
java.io.IOException

writeBool

public void writeBool(boolean b)
               throws java.io.IOException
Called by Xferable.writeXferBytes() for boolean fields. Writes an single byte encoding for true or false.

Throws:
java.io.IOException

writeInt

public void writeInt(int i)
              throws java.io.IOException
Called by Xferable.writeXferBytes() for int fields. Writes a 4 byte int.

Throws:
java.io.IOException

writeRef

public void writeRef(java.lang.Object o)
              throws java.io.IOException
Called by Xferable.writeXferBytes(). Used for Strings, Collections, and any other Object references. Writes -1 for null, otherwise the index to the object's record (4 byte int).

Throws:
java.io.IOException


Copyright © 2008 Joanju Software. All Rights Reserved.