org.globus.wsrf.utils.io
Class IndexedObjectFileWriter

java.lang.Object
  extended byorg.globus.wsrf.utils.io.IndexedObjectFileWriter

public class IndexedObjectFileWriter
extends java.lang.Object

Writes Java objects to an indexed file. The indexing allows for random access to any object in the file. Only Java objects that implement the Serializable interface can be written to the file.

Note: This class is not thread-safe.

See Also:
ObjectOutputStream

Field Summary
private  java.io.ByteArrayOutputStream bos
           
private  java.util.List index
           
private  long indexPointer
           
private  java.io.RandomAccessFile raf
           
 
Constructor Summary
IndexedObjectFileWriter(java.lang.String file)
           
 
Method Summary
 void close()
          Writes the object index and closes the file.
 int getIndexSize()
          Gets the current size of the index (the number of object written so far).
private  void init()
           
 void writeObject(java.lang.Object obj)
          Writes the Java object to the file.
private  void writeObjectSub(java.lang.Object obj)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bos

private java.io.ByteArrayOutputStream bos

raf

private java.io.RandomAccessFile raf

indexPointer

private long indexPointer

index

private java.util.List index
Constructor Detail

IndexedObjectFileWriter

public IndexedObjectFileWriter(java.lang.String file)
                        throws java.io.IOException,
                               java.io.FileNotFoundException
Method Detail

init

private void init()
           throws java.io.IOException
Throws:
java.io.IOException

writeObjectSub

private void writeObjectSub(java.lang.Object obj)
                     throws java.io.IOException
Throws:
java.io.IOException

writeObject

public void writeObject(java.lang.Object obj)
                 throws java.io.IOException
Writes the Java object to the file.

Parameters:
obj - object to write.
Throws:
java.io.IOException - if any error occurs.
See Also:
ObjectOutputStream.writeObject(Object)

getIndexSize

public int getIndexSize()
Gets the current size of the index (the number of object written so far).

Returns:
the current size of the index.

close

public void close()
           throws java.io.IOException
Writes the object index and closes the file. This function must be called, otherwise an incomplete file might be created.

Throws:
java.io.IOException - if any error occurs.