chemaxon.formats
Class MolInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byjava.io.BufferedInputStream
              extended bychemaxon.formats.MolInputStream

public class MolInputStream
extends java.io.BufferedInputStream

Molecule input stream that has the ability to determine the input file format.

Version:
3.3, 01/02/2004
Author:
Peter Csizmadia, Szilard Dorant

Field Summary
 
Fields inherited from class java.io.BufferedInputStream
buf, count, marklimit, markpos, pos
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MolInputStream(java.io.InputStream is)
          Create a molecule input stream from an ordinary one, and determine the format.
MolInputStream(java.io.InputStream is, java.lang.String fmt)
          Create a molecule input stream from an ordinary one, If null is specified as the fmt argument, then the file format is determined automatically.
 
Method Summary
static boolean canBeAbbrevgroup(java.lang.String line)
          Utility function that checks if a string can be in abbrevgroup format.
static boolean canBeBase64(java.lang.String line)
          Utility function that checks if a string can be base64 encoded data.
static boolean canBeChime(java.lang.String s)
          Utility function that checks if a string can be Chime (MDL compressed mol).
static boolean canBeJTF(java.lang.String line)
          Determines if a String is valid as the first line of a JTF file.
static boolean canBeSMARTS(java.lang.String s)
          Utility function that checks if a string can be SMARTS.
static boolean canBeSMILES(java.lang.String s)
          Utility function that checks if a string can be SMILES.
 long getFilePointer()
          Get the file pointer.
 java.lang.String getFormat()
          Get the molecule file format.
static java.util.Vector getJtfFields(java.lang.String line)
          Gets fields delimited with {space} {tab} {;} {:} or {,}.
 int getLineCount()
          Gets the current line number.
 void putBackLine()
          Puts back the last line into the stream.
 int read()
          Reads a character.
 int read(byte[] b, int off, int len)
          Reads a byte array.
 java.lang.String readLine()
          Reads a line.
 void reset()
          Repositions this stream to the position at the time the mark method was last called on this input stream.
 void setFilePointer(long p)
          Sets file pointer and initializes buffer.
 long skip(long n)
          Skips over and discards n bytes of data.
 
Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported
 
Methods inherited from class java.io.FilterInputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MolInputStream

public MolInputStream(java.io.InputStream is,
                      java.lang.String fmt)
               throws java.io.IOException
Create a molecule input stream from an ordinary one, If null is specified as the fmt argument, then the file format is determined automatically. If "mol" or "csmol" is specified, then the file format is determined from the first line from the as "mol", "csmol", "rxn", "csrxn", "rgf" or "csrgf".

Parameters:
is - the original input stream
fmt - the input file format or null
Throws:
java.io.IOException - error occured while trying to guess the file format

MolInputStream

public MolInputStream(java.io.InputStream is)
               throws java.io.IOException
Create a molecule input stream from an ordinary one, and determine the format.

Parameters:
is - the original input stream
Throws:
java.io.IOException - error occured while trying to guess the file format
Method Detail

read

public int read()
         throws java.io.IOException
Reads a character. Warning! This method does not update the line number.

Returns:
the character
Throws:
java.io.IOException - read error occured

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads a byte array. Warning! This method does not update the line number.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data
len - maximum number of bytes to read
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException - read error occured

skip

public long skip(long n)
          throws java.io.IOException
Skips over and discards n bytes of data. Warning! This method does not update the line number.

Parameters:
n - the number of bytes
Returns:
the file pointer after skipping
Throws:
java.io.IOException - read error occured

reset

public void reset()
           throws java.io.IOException
Repositions this stream to the position at the time the mark method was last called on this input stream.

Throws:
java.io.IOException - if this stream has not been marked or if the mark has been invalidated.

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Reads a line.

Returns:
the line without the line separator character(s)
Throws:
java.io.IOException - If an I/O error has occurred.

getLineCount

public int getLineCount()
Gets the current line number. Only lines read with readLine() are counted.

Returns:
the line number

putBackLine

public void putBackLine()
                 throws java.io.IOException
Puts back the last line into the stream. Also repositions the file pointer.

Throws:
java.io.IOException - If an I/O error has occurred.
See Also:
readLine(), getFilePointer()

getFilePointer

public long getFilePointer()
Get the file pointer.

Returns:
the file pointer

setFilePointer

public void setFilePointer(long p)
Sets file pointer and initializes buffer. The stream is not repositioned (use RandomAccessFile.seek) and line count is left unchanged.

Parameters:
p - the file pointer

getFormat

public java.lang.String getFormat()
Get the molecule file format.

Returns:
the format

canBeBase64

public static boolean canBeBase64(java.lang.String line)
Utility function that checks if a string can be base64 encoded data.

Parameters:
line - the input string
Returns:
true if it can be, false if it can not be base 64

canBeAbbrevgroup

public static boolean canBeAbbrevgroup(java.lang.String line)
Utility function that checks if a string can be in abbrevgroup format.

Parameters:
line - the input string
Returns:
true if it can be, false if it can not be abbgrevgroup

canBeSMARTS

public static boolean canBeSMARTS(java.lang.String s)
Utility function that checks if a string can be SMARTS.

Parameters:
s - the input string
Returns:
true if it can be, false if it cannot be SMARTS.

canBeSMILES

public static boolean canBeSMILES(java.lang.String s)
Utility function that checks if a string can be SMILES.

Parameters:
s - the input string
Returns:
true if it can be, false if it cannot be SMILES

canBeChime

public static boolean canBeChime(java.lang.String s)
Utility function that checks if a string can be Chime (MDL compressed mol).

Parameters:
s - the input string
Returns:
true if it can be, false if it cannot be Chime

canBeJTF

public static boolean canBeJTF(java.lang.String line)
Determines if a String is valid as the first line of a JTF file.

Returns:
true, if the line can be a JTF header
Since:
2.9.9

getJtfFields

public static java.util.Vector getJtfFields(java.lang.String line)
Gets fields delimited with {space} {tab} {;} {:} or {,}. Fields are enclosed in "" or '' these can be mixed in a line, but must match for a single field. A valid line for example: "23";'345.45';"asdf asdf";;'CCC1CC1'

Returns:
the contents of the fields.
Since:
2.9.9