List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:com.opengamma.integration.server.copier.ServerDatabasePopulator.java
public void run() throws Exception { Resource res = ResourceUtils.createResource(_configFile); Properties props = new Properties(); try (InputStream in = res.getInputStream()) { if (in == null) { throw new FileNotFoundException(_configFile); }/*from w ww. j a v a2 s. c om*/ props.load(in); } _populatorTool.run(ResourceUtils.toResourceLocator(res), ToolContext.class); }
From source file:de.ingrid.interfaces.csw.tools.FileUtilsTest.java
/** * Test method for// www . java 2s. com * {@link de.ingrid.interfaces.csw.tools.FileUtils#getPackageContent(java.lang.String)} * . */ @Test public void testGetPackageContent() { Resource[] resources = null; try { resources = FileUtils.getPackageContent("classpath*:gdide_test_data/*xml"); } catch (IOException e) { fail("Test failed"); } Assert.isTrue(resources != null); Assert.isTrue(resources.length > 3); try { for (Resource r : resources) { String str = FileUtils.convertStreamToString(r.getInputStream()); Assert.isTrue(str != null && str.length() > 0); } } catch (IOException e) { fail("Test failed"); } }
From source file:lcn.module.batch.core.item.file.ByteReaderFactory.java
/** * Resource encoding? Reader ? //from w ww . jav a2 s . c om * @param resource * @param encoding * @return * @throws UnsupportedEncodingException * @throws IOException */ public ByteReader create(Resource resource, String encoding) throws UnsupportedEncodingException, IOException { return new ByteReader(resource.getInputStream(), encoding); }
From source file:org.openmrs.module.casereport.ClasspathScanningSqlCohortQueryLoader.java
/** * @see SqlCohortQueryLoader#load()//from www. j av a 2 s .c o m */ @Override public List<SqlCohortQuery> load() throws IOException { String pattern = getPathPattern(); if (StringUtils.isBlank(pattern)) { throw new APIException("path pattern is required"); } else if (!pattern.endsWith(".json")) { throw new APIException("path pattern should end with .json"); } Resource[] resources = resourceResolver.getResources("classpath*:/" + pattern); List<SqlCohortQuery> sqlCohortQueries = new ArrayList<SqlCohortQuery>(); for (Resource resource : resources) { sqlCohortQueries.add(getMapper().readValue(resource.getInputStream(), SqlCohortQuery.class)); } return sqlCohortQueries; }
From source file:com.jaxio.celerio.template.pack.ClasspathTemplatePackInfoLoader.java
public List<TemplatePackInfo> resolveTopLevelPacks() { List<TemplatePackInfo> packInfos = newArrayList(); PathMatchingResourcePatternResolver o = new PathMatchingResourcePatternResolver(); try {// w w w . ja v a2 s . co m Resource packInfosAsResource[] = o.getResources(CLASSPATH_CELERIO_PACK); for (Resource r : packInfosAsResource) { CelerioPack celerioPack = celerioPackConfigLoader.load(r.getInputStream()); packInfos.add(new TemplatePackInfo(celerioPack)); } return packInfos; } catch (IOException ioe) { throw new RuntimeException( "Error while searching for Celerio template pack having a META-INF/celerio-pack.xml file!", ioe); } }
From source file:org.swarmcom.jsynapse.TestBase.java
public void getAndCompareResult(String path, Resource req) throws Exception { try (InputStream response = req.getInputStream()) { mockMvc.perform(get(path)).andExpect(status().isOk()) .andExpect(content().string(deleteWhitespace(IOUtils.toString(response)))).andReturn(); }/*from ww w . j a v a2 s .c om*/ }
From source file:com.openmeap.web.servlet.Log4JConfiguratorListener.java
@Override public void contextInitialized(ServletContextEvent arg0) { BasicConfigurator.configure();/*w w w .j a va 2 s . c o m*/ ServletContext servletContext = arg0.getServletContext(); String xmlLoc = servletContext.getInitParameter("openmeap-log4j-xml"); if (xmlLoc == null) { return; } try { Resource res = new ClassPathResource(xmlLoc); DOMConfigurator.configure(XmlUtils.getDocument(res.getInputStream()).getDocumentElement()); } catch (Exception ioe) { servletContext.log("The configuration failed.", ioe); } }
From source file:de.ingrid.interfaces.csw.harvest.impl.TestSuiteHarvester.java
@Override protected List<Serializable> fetchRecords(Date lastExecutionDate) throws Exception { // get list of test datasets Resource[] resources = FileUtils.getPackageContent("classpath*:gdide_test_data/*xml"); List<Serializable> cacheIds = new ArrayList<Serializable>(); statusProvider.addState(this.getId() + "harvesting", "Fetch records... [" + resources.length + "]"); for (Resource resource : resources) { String iso = FileUtils.convertStreamToString(resource.getInputStream()); Record record = IdfTool.createIdfRecord(iso, true); Serializable cacheId = this.cache.put(record); if (log.isDebugEnabled()) { log.debug("Fetched record " + resource.getFilename() + ". Cache id: " + cacheId); }//from ww w . j av a 2s .com cacheIds.add(cacheId); } return cacheIds; }
From source file:com.fns.grivet.service.ClassRegistryServiceTest.java
@Test public void testRegisterThenGetThenAll() throws IOException { Resource r = resolver.getResource("classpath:TestType.json"); String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset()); JSONObject payload = new JSONObject(json); String type = classRegistryService.register(payload); Assertions.assertEquals("TestType", type); JSONObject jo = classRegistryService.get("TestType"); Assertions.assertEquals(payload.toString(), jo.toString()); JSONArray ja = classRegistryService.all(); Assertions.assertEquals(payload.toString(), ja.get(0).toString()); }
From source file:demo.FleetLocationNarrower.java
private List<Map<String, Object>> loadJson(Resource resource) throws IOException, JsonParseException, JsonMappingException { return this.mapper.readValue(resource.getInputStream(), new TypeReference<List<Map<String, Object>>>() { });/*w w w.ja v a 2s . c o m*/ }