chemaxon.marvin.io.formats
Class AbstractMRecordReader

java.lang.Object
  extended by chemaxon.marvin.io.formats.AbstractMRecordReader
All Implemented Interfaces:
MRecordReader

public abstract class AbstractMRecordReader
extends java.lang.Object
implements MRecordReader

Abstract record reader class. It is able to read lines and to create line number mappings for the records.

Since:
Marvin 5.0, 04/26/2007
Version:
5.1.3, 10/18/2008
Author:
Peter Csizmadia, Szilveszter Juhos

Nested Class Summary
 
Nested classes/interfaces inherited from interface chemaxon.marvin.io.MRecordReader
MRecordReader.Position
 
Constructor Summary
AbstractMRecordReader(java.io.InputStream istr, java.lang.String opts)
          Constructs an abstract record reader.
 
Method Summary
protected  void appendLine(java.lang.StringBuffer sb, java.lang.String line)
          Appends line to string buffer with closing '\n' character.
protected  void appendLines(java.lang.StringBuffer sb, java.lang.String l)
          Appends lines to string buffer with closing '\n' character if it is not yet present.
 void close()
          Interrupts parsing.
 chemaxon.util.LongVector detectRecordPositions(chemaxon.util.IntVector linenums)
          Detects positions of records in the input stream.
protected  int[] endRecord(boolean skip)
          It must be called at the end of record.
 MRecordReader getEncapsulatedReader()
          Gets the encapsulated record reader if it exists.
 long getFilePointer()
          Get the file pointer.
 java.lang.String getFooterAsString()
          Gets the footer of the file as a string.
 java.lang.String getHeaderAsString()
          Gets the header of the file as a string.
 int getLineCount()
          Get the current line number.
 MolInputStream getMolInputStream()
          Gets the molecule input stream.
 java.lang.String getOptions()
          Gets the import options.
protected  MRecordReader.Position getPosition()
          Gets the current position.
 java.lang.String getRecognizedFormat()
          Gets the recognized file format.
 boolean isPropertyRecord()
           
 boolean isSeekable()
          Tests whether the record reader is seekable.
protected  void putBackLine()
          Puts back the previous line to the input stream.
protected  java.lang.String readLine()
          Reads the next line.
 void seek(long p, int lcount, int k)
          Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.
 void setProgressMonitor(MProgressMonitor pmon)
          Sets the progress monitor.
protected  boolean skipLine()
          Skips the next line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface chemaxon.marvin.io.MRecordReader
nextRecord, skipRecord
 

Constructor Detail

AbstractMRecordReader

public AbstractMRecordReader(java.io.InputStream istr,
                             java.lang.String opts)
                      throws java.io.IOException
Constructs an abstract record reader.

Parameters:
istr - the input stream
opts - format and options
Throws:
java.io.IOException
Method Detail

setProgressMonitor

public void setProgressMonitor(MProgressMonitor pmon)
Sets the progress monitor. The default implementation does nothing.

Specified by:
setProgressMonitor in interface MRecordReader
Parameters:
pmon - the progress monitor

getRecognizedFormat

public java.lang.String getRecognizedFormat()
Gets the recognized file format.

Specified by:
getRecognizedFormat in interface MRecordReader
Returns:
the input file format

getHeaderAsString

public java.lang.String getHeaderAsString()
Gets the header of the file as a string.

Specified by:
getHeaderAsString in interface MRecordReader
Returns:
empty string in the default implementation
Since:
Marvin 5.0.2, 03/11/2008

getFooterAsString

public java.lang.String getFooterAsString()
Gets the footer of the file as a string.

Specified by:
getFooterAsString in interface MRecordReader
Returns:
empty string in the default implementation
Since:
Marvin 5.0.2, 03/11/2008

getOptions

public java.lang.String getOptions()
Gets the import options.

Specified by:
getOptions in interface MRecordReader
Returns:
the import options

readLine

protected java.lang.String readLine()
                             throws java.io.IOException
Reads the next line.

Returns:
the next line
Throws:
java.io.IOException

skipLine

protected boolean skipLine()
                    throws java.io.IOException
Skips the next line. The skipped line is not stored and cannot put be back into the stream.

Returns:
true if a line was skipped successfully, false at end of file
Throws:
java.io.IOException - If an I/O error has occurred.
Since:
Marvin 5.1.3, 10/18/2008

putBackLine

protected void putBackLine()
                    throws java.io.IOException
Puts back the previous line to the input stream.

Throws:
java.io.IOException

endRecord

protected int[] endRecord(boolean skip)
It must be called at the end of record.

Parameters:
skip - whether to skip the record
Returns:
the line number mapping

close

public void close()
Interrupts parsing.

Specified by:
close in interface MRecordReader

getEncapsulatedReader

public MRecordReader getEncapsulatedReader()
Gets the encapsulated record reader if it exists.

Specified by:
getEncapsulatedReader in interface MRecordReader
Returns:
the encapsulated record reader or null

getMolInputStream

public MolInputStream getMolInputStream()
Gets the molecule input stream.

Specified by:
getMolInputStream in interface MRecordReader
Returns:
the molecule input stream

getFilePointer

public long getFilePointer()
Get the file pointer.

Specified by:
getFilePointer in interface MRecordReader
Returns:
the file pointer

getLineCount

public int getLineCount()
Get the current line number.

Specified by:
getLineCount in interface MRecordReader
Returns:
the line number

isSeekable

public boolean isSeekable()
Tests whether the record reader is seekable.

Specified by:
isSeekable in interface MRecordReader
Returns:
true if it is seekable, false otherwise

seek

public void seek(long p,
                 int lcount,
                 int k)
          throws java.io.IOException
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.

Specified by:
seek in interface MRecordReader
Parameters:
p - the file pointer
lcount - the line count at the specified position
k - the record count at the specified position
Throws:
java.io.IOException - if pos is less than 0 or if an I/O error occurs.

getPosition

protected MRecordReader.Position getPosition()
Gets the current position.

Returns:
the position

appendLines

protected void appendLines(java.lang.StringBuffer sb,
                           java.lang.String l)
Appends lines to string buffer with closing '\n' character if it is not yet present.

Parameters:
sb - the string buffer
l - the lines

appendLine

protected void appendLine(java.lang.StringBuffer sb,
                          java.lang.String line)
Appends line to string buffer with closing '\n' character.

Parameters:
sb - the string buffer
line - the line

isPropertyRecord

public boolean isPropertyRecord()
Specified by:
isPropertyRecord in interface MRecordReader

detectRecordPositions

public chemaxon.util.LongVector detectRecordPositions(chemaxon.util.IntVector linenums)
                                               throws MolFormatException
Detects positions of records in the input stream. Optionally returns also with the line number of records.

Specified by:
detectRecordPositions in interface MRecordReader
Parameters:
linenums - If not null, stores start line numbers of records in this container.
Returns:
container with start and end positions of records (inpair elements describe starting, pairs the ending positions).
Throws:
MolFormatException