PCSubstanceXMLReader extends DefaultChemObjectReader { @Override public <T extends IChemObject> T read(T object) throws CDKException { if (object instanceof IAtomContainer) { try { parserHelper = new PubChemXMLHelper(object.getBuilder()); builder = object.getBuilder(); return (T) readMolecule(); } catch (IOException e) { throw new CDKException("An IO Exception occurred while reading the file.", e); } catch (CDKException e) { throw e; } catch (Exception e) { throw new CDKException("An error occurred: " + e.getMessage(), e); } } else { throw new CDKException("Only supported is reading of ChemFile objects."); } } PCSubstanceXMLReader(Reader input);  PCSubstanceXMLReader(InputStream input);  PCSubstanceXMLReader(); @Override IResourceFormat getFormat(); @Override void setReader(Reader input); @Override void setReader(InputStream input); @Override boolean accepts(Class<? extends IChemObject> classObject); @Override T read(T object); @Override void close();  }
@Test public void testReading() throws Exception { String filename = "data/asn/pubchem/sid577309.xml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); PCSubstanceXMLReader reader = new PCSubstanceXMLReader(ins); IAtomContainer molecule = (IAtomContainer) reader.read(new AtomContainer()); Assert.assertNotNull(molecule); Assert.assertEquals(19, molecule.getAtomCount()); Assert.assertTrue(molecule.getAtom(0) instanceof IPseudoAtom); Assert.assertEquals(19, molecule.getBondCount()); Assert.assertNotNull(molecule.getBond(3)); }