List of usage examples for org.springframework.core.io ClassPathResource getInputStream
@Override public InputStream getInputStream() throws IOException
From source file:nl.surfnet.coin.db.AbstractInMemoryDatabaseTest.java
@After public void afterClass() throws Exception { ClassPathResource resource = new ClassPathResource(getMockDataCleanUpFilename()); if (resource.exists()) { logger.debug("Cleaning database content from " + resource); final String sql = IOUtils.toString(resource.getInputStream()); final String[] split = sql.split(";"); for (String s : split) { if (!StringUtils.hasText(s)) { continue; }//from ww w. j a v a 2s .c om jdbcTemplate.execute(s + ';'); } } }
From source file:nl.surfnet.coin.db.AbstractInMemoryDatabaseTest.java
/** * We use an in-memory database - no need for Spring in this one - and * populate it with the sql statements in test-data-eb.sql * /* w w w . j a v a 2 s . c o m*/ * @throws Exception * unexpected */ @Before public void before() throws Exception { BasicDataSource dataSource = new BasicDataSource(); dataSource.setPassword(""); dataSource.setUsername("sa"); String url = getDataSourceUrl(); dataSource.setUrl(url); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); jdbcTemplate = new JdbcTemplate(dataSource); ClassPathResource resource = new ClassPathResource(getMockDataContentFilename()); logger.debug("Loading database content from " + resource); if (resource.exists()) { final String sql = IOUtils.toString(resource.getInputStream()); final String[] split = sql.split(";"); for (String s : split) { if (!StringUtils.hasText(s)) { continue; } jdbcTemplate.execute(s + ';'); } } }
From source file:org.messic.server.facade.controllers.pages.LoginController.java
/** * Obtain a timestamp based on maven. This timestamp allow to the .css and .js files to force to be updated by the * navigator. If a new version of messic is released, this number will change and the navigator will update those * files.//from w w w. ja v a2 s.c om * * @return {@link String} the timestamp */ private String getTimestamp() { ClassPathResource resource = new ClassPathResource( "/org/messic/server/facade/controllers/pages/timestamp.properties"); Properties p = new Properties(); InputStream inputStream = null; try { inputStream = resource.getInputStream(); p.load(inputStream); } catch (IOException e) { return "12345"; } finally { Closeables.closeQuietly(inputStream); } return p.getProperty("messic.timestamp"); }
From source file:com.goodhuddle.huddle.service.impl.HuddleServiceImpl.java
private PageContent loadDefaultPageContent(String slug) throws HuddleExistsException { try {//from w ww . j a v a 2 s . c o m ClassPathResource resource = new ClassPathResource("/setup/default-" + slug + "-content.json"); try (InputStream in = resource.getInputStream()) { return objectMapper.readValue(in, PageContent.class); } } catch (IOException e) { throw new HuddleExistsException("Error reading default content for '" + slug + "'", e); } }
From source file:org.hisp.dhis.dxf2.importsummary.ImportSummaryTest.java
@Test public void unMarshallImportSummary() throws Exception { ClassPathResource resource = new ClassPathResource("importSummary.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(ImportSummary.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); ImportSummary importSummary = (ImportSummary) jaxbUnmarshaller.unmarshal(resource.getInputStream()); assertEquals(3, importSummary.getDataValueCount().getImported()); assertEquals(0, importSummary.getDataValueCount().getUpdated()); assertEquals(1, importSummary.getDataValueCount().getIgnored()); }