/** * Read an IChemModel from a given file. * @param file * @param type * @param panel * @return * @throws CDKException * @throws FileNotFoundException */ public static IChemModel readFromFile(File file, String type, AbstractJChemPaintPanel panel) throws CDKException, FileNotFoundException { String url = file.toURI().toString(); ISimpleChemObjectReader cor = null; try { cor = FileHandler.createReader(file.toURI().toURL(), url, type); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (cor instanceof CMLReader) cor.setReader(new FileInputStream(file)); // hack else cor.setReader(new FileReader(file)); // hack IChemModel chemModel = JChemPaint.getChemModelFromReader(cor,panel); boolean avoidOverlap=true; if (cor instanceof RGroupQueryReader) avoidOverlap=false; JChemPaint.cleanUpChemModel(chemModel, avoidOverlap, panel); return chemModel; }
/** * Returns the object at given record No. * * Record numbers are zero-based! */ @Override public synchronized IChemObject readRecord(int record) throws Exception { String buffer = readContent(record); if (chemObjectReader == null) throw new CDKException("No chemobject reader!"); else { chemObjectReader.setReader(new StringReader(buffer)); currentRecord = record; return processContent(); } }
/** * Returns the object at given record No. * * Record numbers are zero-based! */ @Override public synchronized IChemObject readRecord(int record) throws Exception { String buffer = readContent(record); if (chemObjectReader == null) throw new CDKException("No chemobject reader!"); else { chemObjectReader.setReader(new StringReader(buffer)); currentRecord = record; return processContent(); } }
@Test(expected = CDKException.class) @Override public void testSetReader_Reader() throws Exception { InputStream ins = ChemObjectReaderTest.class.getClassLoader().getResourceAsStream(testFile); chemObjectIO.setReader(new InputStreamReader(ins)); }
if (reader != null) { try { reader.setReader(input); } catch (CDKException e1) { IOException wrapper = new IOException("Exception while setting the InputStream: " + e1.getMessage()); if (reader != null) { try { reader.setReader(istreamToRead); } catch (CDKException e1) { IOException wrapper = new IOException("Exception while setting the InputStream: " + e1.getMessage());
if (reader != null) { try { reader.setReader(input); } catch (CDKException e1) { IOException wrapper = new IOException("Exception while setting the InputStream: " + e1.getMessage()); if (reader != null) { try { reader.setReader(istreamToRead); } catch (CDKException e1) { IOException wrapper = new IOException("Exception while setting the InputStream: " + e1.getMessage());
/** * 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. * * @see #createReader(InputStream) */ public ISimpleChemObjectReader createReader(Reader input) throws IOException { if (!(input instanceof BufferedReader)) { input = new BufferedReader(input); } IChemFormat chemFormat = formatFactory.guessFormat((BufferedReader) input); ISimpleChemObjectReader coReader = createReader(chemFormat); try { coReader.setReader(input); } catch (Exception exception) { logger.error("Could not set the Reader source: ", exception.getMessage()); logger.debug(exception); } return coReader; }
/** * 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. * * @see #createReader(InputStream) */ public ISimpleChemObjectReader createReader(Reader input) throws IOException { if (!(input instanceof BufferedReader)) { input = new BufferedReader(input); } IChemFormat chemFormat = formatFactory.guessFormat((BufferedReader) input); ISimpleChemObjectReader coReader = createReader(chemFormat); try { coReader.setReader(input); } catch (Exception exception) { logger.error("Could not set the Reader source: ", exception.getMessage()); logger.debug(exception); } return coReader; }
reader.setReader(new StringReader(buffer.toString())); molecule = reader.read(builder.newAtomContainer()); } catch (Exception exception) {
chemReader.setReader(new ByteArrayInputStream(sb.toString() .getBytes()));
@Test public void testRead_IChemObject() throws Exception { Assert.assertNotNull("No test file has been set!", testFile); boolean read = false; for (IChemObject object : acceptableChemObjects()) { if (chemObjectIO.accepts(object.getClass())) { InputStream ins = SimpleChemObjectReaderTest.class.getClassLoader().getResourceAsStream(testFile); chemObjectIO.setReader(ins); IChemObject readObject = chemObjectIO.read(object); chemObjectIO.close(); Assert.assertNotNull("Failed attempt to read the file as " + object.getClass().getName(), readObject); read = true; } } if (!read) { Assert.fail("Reading an IChemObject from the Reader did not work properly."); } }
@Test public void testRead_IChemObject() throws Exception { Assert.assertNotNull("No test file has been set!", testFile); boolean read = false; for (IChemObject object : acceptableChemObjects()) { if (chemObjectIO.accepts(object.getClass())) { InputStream ins = SimpleChemObjectReaderTest.class.getClassLoader().getResourceAsStream(testFile); chemObjectIO.setReader(ins); IChemObject readObject = chemObjectIO.read(object); chemObjectIO.close(); Assert.assertNotNull("Failed attempt to read the file as " + object.getClass().getName(), readObject); read = true; } } if (!read) { Assert.fail("Reading an IChemObject from the Reader did not work properly."); } }
private TestResults testFile(String dir, String filename, ISimpleChemObjectReader reader) throws Exception { CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(DefaultChemObjectBuilder.getInstance()); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(dir + filename); reader.setReader(ins); IAtomContainer mol = null; if (reader.accepts(AtomContainer.class)) {