Package chemaxon.marvin.io
Class MDocSource
java.lang.Object
chemaxon.marvin.io.MDocSource
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<Molecule>
- Direct Known Subclasses:
ArrayMDocSource
,MolImporter
,PluginMDocSource
Marvin document source.
- Since:
- Marvin 4.1, 04/14/2006
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the underlying input stream(s).abstract int
Estimates the total number of records.getDocLabel
(int k, MDocument doc) Returns the display label for the given document and document index.final MoleculeIterator
Gets a molecule iterator for this document source.abstract int
Gets the current record number.abstract int
Gets the total number of records.abstract boolean
Tests whether the end of input is already reached.abstract boolean
Tests whether rewinding (seeking backwards) is possible.iterator()
Gets a molecule iterator for this document source.abstract MDocument
nextDoc()
Produces the next document.final int
seekForward
(int k, MProgressMonitor pmon, int dt, Runnable sizeupdater) Seeks in forward direction.abstract void
seekRecord
(int k, MProgressMonitor pmon) Seeks the specified record.final void
seekRecordAtFraction
(double q, int start, int n, int ncols, MProgressMonitor pmon) Seeks an approximate file position.protected abstract void
seekVisitedRecord
(int k) Seeks an already visited position in case of rewindable input.abstract boolean
Skips the next document.protected final int
skipRecords
(int start, int end, MProgressMonitor pmon, int dt, Runnable sizeupdater) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
MDocSource
public MDocSource()
-
-
Method Details
-
nextDoc
Produces the next document.- Returns:
- the document or null at end of file
- Throws:
IOException
- If I/O error occurred
-
close
Closes the underlying input stream(s). The default implementation does not perform any operation.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If an I/O error has occurred.- Since:
- Marvin 5.2, 02/12/2009
-
getDocLabel
Returns the display label for the given document and document index. The default implementation returnsk+1
as String, wherek
is the document index.- Parameters:
k
- the document indexdoc
- the document- Returns:
- the document label
- Since:
- Marvin 5.0
-
skipRecord
Skips the next document.- Returns:
true
if the end of the next document is found,false
if there is no chance to continue- Throws:
IOException
- If I/O error occurred
-
isRewindable
public abstract boolean isRewindable()Tests whether rewinding (seeking backwards) is possible.- Returns:
true
if rewinding is possible,false
otherwise- See Also:
-
seekRecord
Seeks the specified record. Backward seeking (rewinding) in the stream is only possible if the underlying input stream is seekable. Forward seeking is always possible. Seeking terminates before reaching the specified position if the usercancels
the progress dialog.- Parameters:
k
- positionpmon
- progress monitor ornull
- Throws:
EOFException
- if end of file reached while trying to seekIOException
- if read error occurred- See Also:
-
seekRecordAtFraction
public final void seekRecordAtFraction(double q, int start, int n, int ncols, MProgressMonitor pmon) throws IOException Seeks an approximate file position. To seek the start or end of input, usex
= 0 or 1, respectively. If records correspond to rows and columns of a table and thencols
argument differs from 1, then seeking is restricted to the first column. Backward seeking (rewinding) in the stream is only possible if the underlying input stream is seekable. Forward seeking is always possible. Seeking terminates before reaching the specified position if the usercancels
the progress dialog.- Parameters:
q
- the position divided by the file size, 0 is the start, 1 is the end of filestart
- the minimum record index (offset)n
- the total number of available records or 0 if all records are availablencols
- the number of columns (1 if there are no more columns)pmon
- progress monitor ornull
- Throws:
IOException
- if read error occurred- See Also:
-
seekVisitedRecord
Seeks an already visited position in case of rewindable input.- Parameters:
k
- the record index- Throws:
IOException
- if read error occurred
-
seekForward
public final int seekForward(int k, MProgressMonitor pmon, int dt, Runnable sizeupdater) throws IOException Seeks in forward direction.- Parameters:
k
- the record to seekpmon
- the progress monitordt
- time interval in milliseconds for calling size updatesizeupdater
- optional runnable to be called if the total number of records changed ornull
- Returns:
- the record number where seeking stopped
- Throws:
IOException
- if read error occurred- See Also:
-
skipRecords
protected final int skipRecords(int start, int end, MProgressMonitor pmon, int dt, Runnable sizeupdater) throws IOException - Throws:
IOException
-
getMolStream
-
getMDocumentStream
-
isEndReached
public abstract boolean isEndReached()Tests whether the end of input is already reached.- Returns:
true
if the end was reached,false
otherwise
-
getRecordCount
public abstract int getRecordCount()Gets the current record number.- Returns:
- the record number
-
getRecordCountMax
public abstract int getRecordCountMax()Gets the total number of records.- Returns:
- the number of records
-
estimateNumRecords
public abstract int estimateNumRecords()Estimates the total number of records.Implementations must return -1 in the beginning if the size of the stream is absolutely uncertain. After the first record is parsed, an estimation is returned. The estimation must be greater than the total number of records read so far, unless there are surely no more records. If the total size is still uncertain, then it should return 2 times the current number of records.
- Returns:
- estimated number of records or -1 (at the beginning)
-
iterator
Gets a molecule iterator for this document source. The iterator starts at the current position. Only one iterator can be created for one MolImporter.- Specified by:
iterator
in interfaceIterable<Molecule>
- Returns:
- Iterator
- Throws:
UnsupportedOperationException
- if an iterator was created before- Since:
- Marvin 5.11
-
getMoleculeIterator
Gets a molecule iterator for this document source. The iterator starts at the current position. Only one iterator can be created for one MolImporter.- Returns:
- the molecule iterator
- Throws:
UnsupportedOperationException
- if an iterator was created before- Since:
- Marvin 5.0.2, 03/06/2008
-