org.openscience.cdk.io
Class ReaderFactory

java.lang.Object
  extended by org.openscience.cdk.io.ReaderFactory

public class ReaderFactory
extends Object

A factory for creating ChemObjectReaders. The type of reader created is determined from the content of the input. Formats of GZiped files can be detected too. A typical example is:

   StringReader stringReader = "<molecule/>";
   ChemObjectReader reader = new ReaderFactory().createReader(stringReader);
 

Author:
Egon Willighagen , Bradley A. Smith
Belongs to CDK module:
io
Source code:
HEAD

Constructor Summary
ReaderFactory()
          Constructs a ReaderFactory which tries to detect the format in the first 65536 chars.
ReaderFactory(int headerLength)
          Constructs a ReaderFactory which tries to detect the format in the first given number of chars.
 
Method Summary
 ISimpleChemObjectReader createReader(IChemFormat format)
          Creates a new IChemObjectReader based on the given IChemFormat.
 ISimpleChemObjectReader createReader(InputStream input)
          Detects the format of the Reader input, and if known, it will return a CDK Reader to read the format, or null when the reader is not implemented.
 ISimpleChemObjectReader createReader(Reader input)
          Detects the format of the Reader input, and if known, it will return a CDK Reader to read the format.
 List<IChemFormatMatcher> getFormats()
           
 void registerFormat(IChemFormatMatcher format)
          Registers a format for detection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReaderFactory

public ReaderFactory()
Constructs a ReaderFactory which tries to detect the format in the first 65536 chars.


ReaderFactory

public ReaderFactory(int headerLength)
Constructs a ReaderFactory which tries to detect the format in the first given number of chars.

Parameters:
headerLength - length of the header in number of chars
Method Detail

registerFormat

public void registerFormat(IChemFormatMatcher format)
Registers a format for detection.


getFormats

public List<IChemFormatMatcher> getFormats()

createReader

public ISimpleChemObjectReader createReader(InputStream input)
                                     throws IOException
Detects the format of the Reader input, and if known, it will return a CDK Reader to read the format, or null when the reader is not implemented.

Returns:
null if CDK does not contain a reader for the detected format.
Throws:
IOException
See Also:
createReader(Reader)

createReader

public ISimpleChemObjectReader createReader(IChemFormat format)
Creates a new IChemObjectReader based on the given IChemFormat.

See Also:
createReader(InputStream)

createReader

public ISimpleChemObjectReader createReader(Reader input)
                                     throws IOException
Detects the format of the Reader input, and if known, it will return a CDK Reader to read the format. This method is not able to detect the format of gziped files. Use createReader(InputStream) instead for such files.

Throws:
IOException
See Also:
createReader(InputStream)