Package chemaxon.marvin.io.formats
Class AbstractMRecordReader
- java.lang.Object
-
- chemaxon.marvin.io.formats.AbstractMRecordReader
-
- All Implemented Interfaces:
MRecordReader
@PublicAPI public abstract class AbstractMRecordReader extends 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface chemaxon.marvin.io.MRecordReader
MRecordReader.Position
-
-
Constructor Summary
Constructors Modifier Constructor Description AbstractMRecordReader(InputStream istr, String opts)
Constructs an abstract record reader.protected
AbstractMRecordReader(InputStream istr, String opts, String path)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
appendLine(StringBuffer sb, String line)
Appends line to string buffer with closing '\n' character.protected void
appendLines(StringBuffer sb, String l)
Appends lines to string buffer with closing '\n' character if it is not yet present.void
close()
Interrupts parsing.chemaxon.common.util.LongVector
detectRecordPositions(chemaxon.common.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.String
getFooterAsString()
Gets the footer of the file as a string.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.String
getOptions()
Gets the import options.protected MRecordReader.Position
getPosition()
Gets the current position.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 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(InputStream istr, String opts) throws IOException
Constructs an abstract record reader.- Parameters:
istr
- the input streamopts
- format and options- Throws:
IOException
-
AbstractMRecordReader
protected AbstractMRecordReader(InputStream istr, String opts, String path) throws IOException
- Throws:
IOException
-
-
Method Detail
-
setProgressMonitor
public void setProgressMonitor(MProgressMonitor pmon)
Sets the progress monitor. The default implementation does nothing.- Specified by:
setProgressMonitor
in interfaceMRecordReader
- Parameters:
pmon
- the progress monitor
-
getRecognizedFormat
public String getRecognizedFormat()
Gets the recognized file format.- Specified by:
getRecognizedFormat
in interfaceMRecordReader
- Returns:
- the input file format
-
getHeaderAsString
public String getHeaderAsString()
Gets the header of the file as a string.- Specified by:
getHeaderAsString
in interfaceMRecordReader
- Returns:
- empty string in the default implementation
- Since:
- Marvin 5.0.2, 03/11/2008
-
getFooterAsString
public String getFooterAsString()
Gets the footer of the file as a string.- Specified by:
getFooterAsString
in interfaceMRecordReader
- Returns:
- empty string in the default implementation
- Since:
- Marvin 5.0.2, 03/11/2008
-
getOptions
public String getOptions()
Gets the import options.- Specified by:
getOptions
in interfaceMRecordReader
- Returns:
- the import options
-
readLine
protected String readLine() throws IOException
Reads the next line.- Returns:
- the next line
- Throws:
IOException
-
skipLine
protected boolean skipLine() throws 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:
IOException
- If an I/O error has occurred.- Since:
- Marvin 5.1.3, 10/18/2008
-
putBackLine
protected void putBackLine() throws IOException
Puts back the previous line to the input stream.- Throws:
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 interfaceMRecordReader
-
getEncapsulatedReader
public MRecordReader getEncapsulatedReader()
Gets the encapsulated record reader if it exists.- Specified by:
getEncapsulatedReader
in interfaceMRecordReader
- Returns:
- the encapsulated record reader or
null
-
getMolInputStream
public MolInputStream getMolInputStream()
Gets the molecule input stream.- Specified by:
getMolInputStream
in interfaceMRecordReader
- Returns:
- the molecule input stream
-
getFilePointer
public long getFilePointer()
Get the file pointer.- Specified by:
getFilePointer
in interfaceMRecordReader
- Returns:
- the file pointer
-
getLineCount
public int getLineCount()
Get the current line number.- Specified by:
getLineCount
in interfaceMRecordReader
- Returns:
- the line number
-
isSeekable
public boolean isSeekable()
Tests whether the record reader is seekable.- Specified by:
isSeekable
in interfaceMRecordReader
- Returns:
true
if it is seekable,false
otherwise
-
seek
public void seek(long p, int lcount, int k) throws 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 interfaceMRecordReader
- Parameters:
p
- the file pointerlcount
- the line count at the specified positionk
- the record count at the specified position- Throws:
IOException
- ifpos
is less than0
or if an I/O error occurs.
-
getPosition
protected MRecordReader.Position getPosition()
Gets the current position.- Returns:
- the position
-
appendLines
protected void appendLines(StringBuffer sb, String l)
Appends lines to string buffer with closing '\n' character if it is not yet present.- Parameters:
sb
- the string bufferl
- the lines
-
appendLine
protected void appendLine(StringBuffer sb, String line)
Appends line to string buffer with closing '\n' character.- Parameters:
sb
- the string bufferline
- the line
-
isPropertyRecord
public boolean isPropertyRecord()
- Specified by:
isPropertyRecord
in interfaceMRecordReader
-
detectRecordPositions
public chemaxon.common.util.LongVector detectRecordPositions(chemaxon.common.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 interfaceMRecordReader
- 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
-
-