Class FormatFactory


public class FormatFactory extends Object
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);
Egon Willighagen <>, Bradley A. Smith <>
Source code:
Belongs to CDK module:
  • 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.
      headerLength - length of the header in number of chars
  • Method Details

    • registerFormat

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

      public List<IChemFormatMatcher> getFormats()
      Returns the list of recognizable formats.
      List of IChemFormats.
    • guessFormat

      public IChemFormat guessFormat(Reader input) throws IOException
      Creates a String of the Class name of the IChemObject 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.

      The guessed IChemFormat or null if the file format is not recognized.
      IOException - if an I/O error occurs
      IllegalArgumentException - if the input is null
      See Also:
    • guessFormat

      public IChemFormat guessFormat(InputStream input) throws IOException