Package org.openscience.cdk.io
Class FormatFactory
java.lang.Object
org.openscience.cdk.io.FormatFactory
A factory for recognizing chemical file formats. Formats
of GZiped files can be detected too.
A typical example is:
StringReader stringReader = new StringReader("<molecule/>");
IChemFormat format = new FormatFactory().guessFormat(stringReader);
- Author:
- Egon Willighagen <egonw@sci.kun.nl>, Bradley A. Smith <bradley@baysmith.com>
- Source code:
- main
- Belongs to CDK module:
- ioformats
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a ReaderFactory which tries to detect the format in the first 65536 chars.FormatFactory
(int headerLength) Constructs a ReaderFactory which tries to detect the format in the first given number of chars. -
Method Summary
Modifier and TypeMethodDescriptionReturns the list of recognizable formats.guessFormat
(InputStream input) guessFormat
(Reader input) Creates a String of the Class name of theIChemObject
reader for this file format.void
registerFormat
(IChemFormatMatcher format) Registers a format for detection.
-
Constructor Details
-
FormatFactory
public FormatFactory()Constructs a ReaderFactory which tries to detect the format in the first 65536 chars. -
FormatFactory
public FormatFactory(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 Details
-
registerFormat
Registers a format for detection. -
getFormats
Returns the list of recognizable formats.- Returns:
List
ofIChemFormat
s.
-
guessFormat
Creates a String of the Class name of theIChemObject
reader for this file format. The input is read line-by-line until a line containing an identifying string is found.The ReaderFactory detects more formats than the CDK has Readers for.
This method is not able to detect the format of gziped files. Use
guessFormat(InputStream)
instead for such files.- Returns:
- The guessed
IChemFormat
ornull
if the file format is not recognized. - Throws:
IOException
- if an I/O error occursIllegalArgumentException
- if the input is null- See Also:
-
guessFormat
- Throws:
IOException
-