Package org.openscience.cdk.io
Class ReaderFactory
- java.lang.Object
-
- 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/>"; ISimpleChemObjectReader reader = new ReaderFactory().createReader(stringReader);
- Author:
- Egon Willighagen <egonw@sci.kun.nl>, Bradley A. Smith <bradley@baysmith.com>
- Source code:
- main
- Belongs to CDK module:
- io
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.ISimpleChemObjectReader
createReader(IChemFormat format)
Creates a new IChemObjectReader based on the given IChemFormat.List<IChemFormatMatcher>
getFormats()
void
registerFormat(IChemFormatMatcher format)
Registers a format for detection.
-
-
-
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)
-
-