Class MDocSource

java.lang.Object
chemaxon.marvin.io.MDocSource
All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<Molecule>
Direct Known Subclasses:
ArrayMDocSource, MolImporter

@PublicAPI public abstract class MDocSource extends Object implements Iterable<Molecule>, Closeable
Marvin document source.
Since:
Marvin 4.1, 04/14/2006
  • Constructor Details

    • MDocSource

      public MDocSource()
  • Method Details

    • nextDoc

      public abstract MDocument nextDoc() throws IOException
      Produces the next document.
      Returns:
      the document or null at end of file
      Throws:
      IOException - If I/O error occurred
    • close

      public void close() throws IOException
      Closes the underlying input stream(s). The default implementation does not perform any operation.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - If an I/O error has occurred.
      Since:
      Marvin 5.2, 02/12/2009
    • getDocLabel

      public String getDocLabel(int k, MDocument doc)
      Returns the display label for the given document and document index. The default implementation returns k+1 as String, where k is the document index.
      Parameters:
      k - the document index
      doc - the document
      Returns:
      the document label
      Since:
      Marvin 5.0
    • skipRecord

      public abstract boolean skipRecord() throws IOException
      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

      public abstract void seekRecord(int k, MProgressMonitor pmon) throws IOException
      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 user cancels the progress dialog.
      Parameters:
      k - position
      pmon - progress monitor or null
      Throws:
      EOFException - if end of file reached while trying to seek
      IOException - 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, use x = 0 or 1, respectively. If records correspond to rows and columns of a table and the ncols 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 user cancels the progress dialog.
      Parameters:
      q - the position divided by the file size, 0 is the start, 1 is the end of file
      start - the minimum record index (offset)
      n - the total number of available records or 0 if all records are available
      ncols - the number of columns (1 if there are no more columns)
      pmon - progress monitor or null
      Throws:
      IOException - if read error occurred
      See Also:
    • seekVisitedRecord

      protected abstract void seekVisitedRecord(int k) throws IOException
      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 seek
      pmon - the progress monitor
      dt - time interval in milliseconds for calling size update
      sizeupdater - optional runnable to be called if the total number of records changed or null
      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

      protected Stream<Molecule> getMolStream()
    • getMDocumentStream

      protected Stream<MDocument> 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

      public Iterator<Molecule> 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 interface Iterable<Molecule>
      Returns:
      Iterator
      Throws:
      UnsupportedOperationException - if an iterator was created before
      Since:
      Marvin 5.11
    • getMoleculeIterator

      public final MoleculeIterator 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