lempinen.util
Class RandomAccessArray

java.lang.Object
  |
  +--lempinen.util.RandomAccessArray
Direct Known Subclasses:
TargetIndex

public class RandomAccessArray
extends java.lang.Object

Class for storing and retrieving objects from a random access file.

This class serves the purpose of providing a persistent storage of Serializable objects. It provides fast access to the objects using a Long identifier, which is in fact the byte offset of the object from the beginning of the file. This makes the identifiers unique. The name Array is really a bit of a misnomer, as the index numbers do not run sequentially. Futhermore, once an Object has been added, it cannot be safely replaced or deleted, as the individual objects can be of any type and therefore of a varying size.

This class was developed in order to speed up reading a NeatSeeker TargetIndex. Indexes of > 10000 HTML documents had a noticeable (over 10s) bottleneck when deserializing the old TreeMap format TargetIndex.

Version:
$Id: RandomAccessArray.java,v 1.1.1.1 2000/09/23 07:29:27 lempinen Exp $
Author:
Sami Lempinen

Field Summary
protected  java.io.RandomAccessFile rafile
          The file to use for serializing the objects.
 
Constructor Summary
RandomAccessArray(java.lang.String file)
          Creates a new RandomAccessArray object in read-write mode.
RandomAccessArray(java.lang.String file, boolean readonly)
          Creates a new RandomAccessArray object (read or read-write).
 
Method Summary
 java.io.Serializable get(long id)
          Returns the object indicated by the ID.
 long getNextID()
          Returns the ID of the next put() operation.
 long put(java.io.Serializable s)
          Adds an object into the index and returns a unique ID.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

rafile

protected java.io.RandomAccessFile rafile
The file to use for serializing the objects.
Constructor Detail

RandomAccessArray

public RandomAccessArray(java.lang.String file)
                  throws java.io.IOException
Creates a new RandomAccessArray object in read-write mode.

RandomAccessArray

public RandomAccessArray(java.lang.String file,
                         boolean readonly)
                  throws java.io.IOException
Creates a new RandomAccessArray object (read or read-write).
Method Detail

getNextID

public long getNextID()
               throws java.io.IOException
Returns the ID of the next put() operation.

put

public long put(java.io.Serializable s)
         throws java.io.IOException
Adds an object into the index and returns a unique ID.

get

public java.io.Serializable get(long id)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Returns the object indicated by the ID.