Class RandomAccessReader
java.lang.Object
org.openscience.cdk.io.random.DefaultRandomAccessChemObjectReader
org.openscience.cdk.io.random.RandomAccessReader
- All Implemented Interfaces:
Iterator<IChemObject>, ListIterator<IChemObject>, IRandomAccessChemObjectReader<IChemObject>
- Direct Known Subclasses:
RandomAccessSDFReader
public abstract class RandomAccessReader
extends DefaultRandomAccessChemObjectReader
implements IRandomAccessChemObjectReader<IChemObject>
Random access to text files of compounds.
Reads the file as a text and builds an index file, if the index file doesn't already exist.
The index stores offset, length and a third field reserved for future use.
Subsequent access for a record N uses this index to seek the record and return the molecule.
Useful for very big files.
- Author:
- Nina Jeliazkova <nina@acad.bg>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]protected final IChemObjectBuilderprotected ISimpleChemObjectReaderprotected intprotected IOSetting[]protected long[][]protected booleanprotected final intprotected static final ILoggingToolprotected RandomAccessFileprotected intFields inherited from class DefaultRandomAccessChemObjectReader
mode -
Constructor Summary
ConstructorsConstructorDescriptionRandomAccessReader(File file, IChemObjectBuilder builder) Reads the file and builds an index file, if the index file doesn't already exist.RandomAccessReader(File file, IChemObjectBuilder builder, IReaderListener listener) Reads the file and builds an index file, if the index file doesn't already exist. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(IChemObject arg0) voidaddChemObjectIOListener(IChemObjectIOListener listener) voidclose()abstract ISimpleChemObjectReaderprotected voidfinalize()first()intstatic FilegetIndexFile(String filename) Opens the file index file_cdk.indexin a temporary folder, as specified by "java.io.tmpdir" property.booleanhasNext()booleanbooleanprotected abstract booleanisRecordEnd(String line) last()protected voidprotected voidThe index filegetIndexFile(String)is loaded, if already exists, or created a new.next()intprevious()intprotected IChemObjectThe reader is already set to read the record buffer.protected StringreadContent(int record) Reads the record text content into a String.readRecord(int record) Returns the object at given record No.voidprotected long[][]resize(long[][] index, int newLength) protected voidvoidset(IChemObject arg0) voidsetChemObjectReader(ISimpleChemObjectReader chemObjectReader) voidsetIndexCreated(boolean indexCreated) intsize()toString()Methods inherited from class DefaultRandomAccessChemObjectReader
fireIOSettingQuestion, getIOSettings, setReaderModeMethods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterator
forEachRemainingMethods inherited from interface ListIterator
remove
-
Field Details
-
logger
-
raFile
-
headerOptions
-
chemObjectReader
-
indexVersion
protected final int indexVersion- See Also:
-
index
protected long[][] index -
records
protected int records -
currentRecord
protected int currentRecord -
b
protected byte[] b -
builder
-
indexCreated
protected boolean indexCreated
-
-
Constructor Details
-
RandomAccessReader
Reads the file and builds an index file, if the index file doesn't already exist.- Parameters:
file- the file object containing the molecules to be indexedbuilder- a chem object builder- Throws:
IOException- if there is an error during reading
-
RandomAccessReader
public RandomAccessReader(File file, IChemObjectBuilder builder, IReaderListener listener) throws IOException Reads the file and builds an index file, if the index file doesn't already exist.- Parameters:
file- file the file object containg the molecules to be indexedbuilder- builder a chem object builderlistener- listen for read event- Throws:
IOException- if there is an error during reading
-
-
Method Details
-
finalize
-
readRecord
Returns the object at given record No. Record numbers are zero-based!- Specified by:
readRecordin interfaceIRandomAccessChemObjectReader<IChemObject>- Throws:
Exception
-
readContent
Reads the record text content into a String.- Parameters:
record- The record number- Returns:
- A String representation of the record
- Throws:
IOException- if error occurs during readingCDKException- if the record number is invalid
-
processContent
The reader is already set to read the record buffer.- Returns:
- the read IChemObject
- Throws:
CDKException- an error occurred whilst reading the file
-
resize
protected long[][] resize(long[][] index, int newLength) -
isRecordEnd
-
saveIndex
-
loadIndex
-
makeIndex
The index filegetIndexFile(String)is loaded, if already exists, or created a new.- Throws:
Exception
-
getIndexFile
-
close
- Throws:
IOException
-
getChemObjectReader
-
createChemObjectReader
-
setChemObjectReader
-
hasNext
public boolean hasNext()- Specified by:
hasNextin interfaceIterator<IChemObject>- Specified by:
hasNextin interfaceListIterator<IChemObject>
-
hasPrevious
public boolean hasPrevious()- Specified by:
hasPreviousin interfaceListIterator<IChemObject>
-
first
- Specified by:
firstin interfaceIRandomAccessChemObjectReader<IChemObject>
-
last
- Specified by:
lastin interfaceIRandomAccessChemObjectReader<IChemObject>
-
next
- Specified by:
nextin interfaceIterator<IChemObject>- Specified by:
nextin interfaceListIterator<IChemObject>
-
previous
- Specified by:
previousin interfaceListIterator<IChemObject>
-
set
- Specified by:
setin interfaceListIterator<IChemObject>
-
add
- Specified by:
addin interfaceListIterator<IChemObject>
-
previousIndex
public int previousIndex()- Specified by:
previousIndexin interfaceListIterator<IChemObject>
-
nextIndex
public int nextIndex()- Specified by:
nextIndexin interfaceListIterator<IChemObject>
-
size
public int size()- Specified by:
sizein interfaceIRandomAccessChemObjectReader<IChemObject>
-
addChemObjectIOListener
- Overrides:
addChemObjectIOListenerin classDefaultRandomAccessChemObjectReader
-
removeChemObjectIOListener
- Overrides:
removeChemObjectIOListenerin classDefaultRandomAccessChemObjectReader
-
getCurrentRecord
public int getCurrentRecord() -
isIndexCreated
public boolean isIndexCreated() -
setIndexCreated
public void setIndexCreated(boolean indexCreated) -
toString
-