ambit2.core.io
Class RandomAccessReader

Package class diagram package RandomAccessReader
java.lang.Object
  extended by org.openscience.cdk.io.iterator.DefaultIteratingChemObjectReader
      extended by ambit2.core.io.RandomAccessReader
All Implemented Interfaces:
ambit2.base.interfaces.IRandomAccessChemObjectReader, java.lang.Runnable, java.util.Iterator, java.util.ListIterator, org.openscience.cdk.io.IChemObjectIO, org.openscience.cdk.io.iterator.IIteratingChemObjectReader
Direct Known Subclasses:
RandomAccessSDFReader

public abstract class RandomAccessReader
extends org.openscience.cdk.io.iterator.DefaultIteratingChemObjectReader
implements ambit2.base.interfaces.IRandomAccessChemObjectReader, java.lang.Runnable

Random access to text files of compounds. First reads the file and builds an index in memory. The index stores offset, length and number of atoms of the molecule in that record. Subsequent access for a record N uses this index to seek the record and return the molecule. Useful for very big files.


Field Summary
protected  byte[] b
           
protected  org.openscience.cdk.interfaces.IChemObjectBuilder builder
           
protected  org.openscience.cdk.io.IChemObjectReader chemObjectReader
           
protected  int currentRecord
           
protected  org.openscience.cdk.io.setting.IOSetting[] headerOptions
           
protected  long[][] index
           
protected  boolean indexCreated
           
protected  int indexVersion
           
protected static org.openscience.cdk.tools.LoggingTool logger
           
protected  java.io.RandomAccessFile raFile
           
protected  int records
           
 
Constructor Summary
RandomAccessReader(java.io.File file, org.openscience.cdk.interfaces.IChemObjectBuilder builder)
           
RandomAccessReader(java.io.File file, org.openscience.cdk.interfaces.IChemObjectBuilder builder, org.openscience.cdk.io.listener.IReaderListener listener)
           
 
Method Summary
 void add(java.lang.Object arg0)
           
 void addChemObjectIOListener(org.openscience.cdk.io.listener.IChemObjectIOListener listener)
           
 void close()
           
abstract  org.openscience.cdk.io.IChemObjectReader createChemObjectReader()
           
protected  void finalize()
           
 java.lang.Object first()
           
 org.openscience.cdk.io.IChemObjectReader getChemObjectReader()
           
 int getCurrentRecord()
           
static java.io.File getIndexFile(java.lang.String filename)
           
 int getNumberOfRecords()
           
 boolean hasNext()
           
 boolean hasPrevious()
           
 boolean isIndexCreated()
           
protected abstract  boolean isRecordEnd(java.lang.String line)
           
 java.lang.Object last()
           
protected  void loadIndex(java.io.File file)
           
protected  void makeIndex()
           
 java.lang.Object next()
           
 int nextIndex()
           
 java.lang.Object previous()
           
 int previousIndex()
           
 int read(char[] cbuf, int off, int len)
           
 java.lang.Object readContent(java.lang.String buffer, int length)
           
 java.lang.Object readRecord(int record)
           
 void removeChemObjectIOListener(org.openscience.cdk.io.listener.IChemObjectIOListener listener)
           
protected  long[][] resize(long[][] index, int newLength)
           
 void run()
           
protected  void saveIndex(java.io.File file)
           
 void set(java.lang.Object arg0)
           
 void setChemObjectReader(org.openscience.cdk.io.IChemObjectReader chemObjectReader)
           
 void setIndexCreated(boolean indexCreated)
           
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class org.openscience.cdk.io.iterator.DefaultIteratingChemObjectReader
accepts, fireFrameRead, fireIOSettingQuestion, getIOSettings, remove
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.ListIterator
remove
 
Methods inherited from interface org.openscience.cdk.io.IChemObjectIO
getFormat
 

Field Detail

logger

protected static org.openscience.cdk.tools.LoggingTool logger

raFile

protected java.io.RandomAccessFile raFile

headerOptions

protected org.openscience.cdk.io.setting.IOSetting[] headerOptions

chemObjectReader

protected org.openscience.cdk.io.IChemObjectReader chemObjectReader

indexVersion

protected int indexVersion

index

protected long[][] index

records

protected int records

currentRecord

protected int currentRecord

b

protected byte[] b

builder

protected org.openscience.cdk.interfaces.IChemObjectBuilder builder

indexCreated

protected boolean indexCreated
Constructor Detail

RandomAccessReader

public RandomAccessReader(java.io.File file,
                          org.openscience.cdk.interfaces.IChemObjectBuilder builder)
                   throws java.io.IOException
Throws:
java.io.IOException

RandomAccessReader

public RandomAccessReader(java.io.File file,
                          org.openscience.cdk.interfaces.IChemObjectBuilder builder,
                          org.openscience.cdk.io.listener.IReaderListener listener)
                   throws java.io.IOException
Throws:
java.io.IOException
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

readRecord

public java.lang.Object readRecord(int record)
                            throws java.lang.Exception
Specified by:
readRecord in interface ambit2.base.interfaces.IRandomAccessChemObjectReader
Throws:
java.lang.Exception

readContent

public java.lang.Object readContent(java.lang.String buffer,
                                    int length)
                             throws org.openscience.cdk.exception.CDKException
Throws:
org.openscience.cdk.exception.CDKException

resize

protected long[][] resize(long[][] index,
                          int newLength)

isRecordEnd

protected abstract boolean isRecordEnd(java.lang.String line)

saveIndex

protected void saveIndex(java.io.File file)
                  throws java.lang.Exception
Throws:
java.lang.Exception

loadIndex

protected void loadIndex(java.io.File file)
                  throws java.lang.Exception
Throws:
java.lang.Exception

makeIndex

protected void makeIndex()
                  throws java.io.IOException
Throws:
java.io.IOException

getIndexFile

public static java.io.File getIndexFile(java.lang.String filename)

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface org.openscience.cdk.io.IChemObjectIO
Throws:
java.io.IOException

getChemObjectReader

public org.openscience.cdk.io.IChemObjectReader getChemObjectReader()

createChemObjectReader

public abstract org.openscience.cdk.io.IChemObjectReader createChemObjectReader()

setChemObjectReader

public void setChemObjectReader(org.openscience.cdk.io.IChemObjectReader chemObjectReader)

getNumberOfRecords

public int getNumberOfRecords()

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator
Specified by:
hasNext in interface java.util.ListIterator

hasPrevious

public boolean hasPrevious()
Specified by:
hasPrevious in interface java.util.ListIterator

first

public java.lang.Object first()
Specified by:
first in interface ambit2.base.interfaces.IRandomAccessChemObjectReader

last

public java.lang.Object last()
Specified by:
last in interface ambit2.base.interfaces.IRandomAccessChemObjectReader

next

public java.lang.Object next()
Specified by:
next in interface java.util.Iterator
Specified by:
next in interface java.util.ListIterator

previous

public java.lang.Object previous()
Specified by:
previous in interface java.util.ListIterator

set

public void set(java.lang.Object arg0)
Specified by:
set in interface java.util.ListIterator

add

public void add(java.lang.Object arg0)
Specified by:
add in interface java.util.ListIterator

previousIndex

public int previousIndex()
Specified by:
previousIndex in interface java.util.ListIterator

nextIndex

public int nextIndex()
Specified by:
nextIndex in interface java.util.ListIterator

size

public int size()
Specified by:
size in interface ambit2.base.interfaces.IRandomAccessChemObjectReader

addChemObjectIOListener

public void addChemObjectIOListener(org.openscience.cdk.io.listener.IChemObjectIOListener listener)
Specified by:
addChemObjectIOListener in interface org.openscience.cdk.io.IChemObjectIO
Overrides:
addChemObjectIOListener in class org.openscience.cdk.io.iterator.DefaultIteratingChemObjectReader

removeChemObjectIOListener

public void removeChemObjectIOListener(org.openscience.cdk.io.listener.IChemObjectIOListener listener)
Specified by:
removeChemObjectIOListener in interface org.openscience.cdk.io.IChemObjectIO
Overrides:
removeChemObjectIOListener in class org.openscience.cdk.io.iterator.DefaultIteratingChemObjectReader

getCurrentRecord

public int getCurrentRecord()

isIndexCreated

public boolean isIndexCreated()

setIndexCreated

public void setIndexCreated(boolean indexCreated)

run

public void run()
Specified by:
run in interface java.lang.Runnable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object