ISimpleChemObjectReader reader = null; if (input instanceof GZIPInputStream) { format = formatFactory.guessFormat(input); reader = createReader(format); if (reader != null) { format = formatFactory.guessFormat(istreamToRead); reader = createReader(format); if (reader != null) {
ISimpleChemObjectReader reader = null; if (input instanceof GZIPInputStream) { format = formatFactory.guessFormat(input); reader = createReader(format); if (reader != null) { format = formatFactory.guessFormat(istreamToRead); reader = createReader(format); if (reader != null) {
/** * 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; }
/** * Test that the format factory guesses the correct IChemFormat * based on the file content. * * @throws Exception */ @Test public void testRGFileFormat() throws Exception { String filename = "data/mdl/rgfile.1.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); IChemFormat format = new FormatFactory().guessFormat(new BufferedInputStream(ins)); Assert.assertEquals(format.getClass(), RGroupQueryFormat.class); }
@Test public void testGuessFormat_Gz() throws Exception { String filename = "data/xyz/bf3.xyz.gz"; InputStream input = new BufferedInputStream(new GZIPInputStream(this.getClass().getClassLoader() .getResourceAsStream(filename))); IChemFormat format = factory.guessFormat(input); Assert.assertNotNull(format); // make sure the InputStream is properly reset BufferedReader reader = new BufferedReader(new InputStreamReader(input)); String line = reader.readLine(); Assert.assertNotNull(line); Assert.assertEquals("4", line); line = reader.readLine(); Assert.assertNotNull(line); Assert.assertEquals("Bortrifluorid", line); }
@Test public void testGuessFormat_Reader() throws Exception { String filename = "data/xyz/bf3.xyz"; InputStream input = this.getClass().getClassLoader().getResourceAsStream(filename); BufferedReader reader = new BufferedReader(new InputStreamReader(input)); IChemFormat format = factory.guessFormat(reader); Assert.assertNotNull(format); // make sure the Reader is properly reset String line = reader.readLine(); Assert.assertNotNull(line); Assert.assertEquals("4", line); line = reader.readLine(); Assert.assertNotNull(line); Assert.assertEquals("Bortrifluorid", line); }
IChemFormat format=formatFactory.guessFormat(input);
private void expectFormat(String filename, IResourceFormat expectedFormat) throws Exception { InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); Assert.assertNotNull("Cannot find file: " + filename, ins); if (expectedFormat instanceof IChemFormatMatcher) { factory.registerFormat((IChemFormatMatcher) expectedFormat); } ins = new BufferedInputStream(ins); IChemFormat format = factory.guessFormat(ins); Assert.assertNotNull(format); Assert.assertEquals(expectedFormat.getFormatName(), format.getFormatName()); }
/** * @cdk.bug 2153298 */ @Test public void testGuessFormat() throws Exception { String filename = "data/xyz/bf3.xyz"; InputStream input = this.getClass().getClassLoader().getResourceAsStream(filename); input = new BufferedInputStream(input); IChemFormat format = factory.guessFormat(input); Assert.assertNotNull(format); // make sure the InputStream is properly reset BufferedReader reader = new BufferedReader(new InputStreamReader(input)); String line = reader.readLine(); Assert.assertNotNull(line); Assert.assertEquals("4", line); line = reader.readLine(); Assert.assertNotNull(line); Assert.assertEquals("Bortrifluorid", line); }
@Test public void testRegisterFormat() throws IOException { factory.registerFormat(new DummyFormat()); StringReader reader = new StringReader("DummyFormat:"); IChemFormat format = factory.guessFormat(reader); Assert.assertNotNull(format); Assert.assertTrue(format instanceof DummyFormat); } }