List of usage examples for org.springframework.core.io ClassPathResource getInputStream
@Override public InputStream getInputStream() throws IOException
From source file:ru.anr.base.services.api.MockJSONAPICommandFactoryImpl.java
/** * Loading a file from classpath/* w w w . ja va 2 s. c o m*/ * * @param filePath * (relative from classpath) * @return File content */ protected String loadFromFile(String filePath) { try { ClassPathResource r = new ClassPathResource(filePath); return IOUtils.toString(r.getInputStream(), "utf-8"); } catch (IOException ex) { throw new ApplicationException(ex); } }
From source file:edu.northwestern.bioinformatics.studycalendar.restlets.ClasspathResourceRepresentation.java
@Override public InputStream getStream() throws IOException { ClassPathResource res = new ClassPathResource(resourceName); if (!res.exists()) { throw new FileNotFoundException("Could not find " + resourceName); }//from w w w .j a v a2 s . co m return res.getInputStream(); }
From source file:$.ChangesController.java
@RequestMapping(value = CHANGES_URI, method = RequestMethod.GET) @ResponseBody//from ww w. j ava 2 s.com public String getChangesContent() throws IOException { ClassPathResource resource = new ClassPathResource("changes.txt"); // add end of lines String resStr = ""; List<String> lines = IOUtils.readLines(resource.getInputStream(), "utf-8"); for (String line : lines) { resStr += line; resStr += "<br/>${symbol_escape}n"; } return resStr; }
From source file:org.energyos.espi.thirdparty.mocks.MockRestTemplate.java
@SuppressWarnings("unchecked") public <T> T getForObject(String url, Class<T> responseType, Object... urlVariables) throws RestClientException { ClassPathResource sourceFile = new ClassPathResource("/fixtures/test_usage_data.xml"); String inputStreamString;//from w w w. java 2 s . c o m try { inputStreamString = new Scanner(sourceFile.getInputStream(), "UTF-8").useDelimiter("\\A").next(); return (T) inputStreamString; } catch (IOException e) { e.printStackTrace(); throw new RestClientException("The file import broke."); } }
From source file:org.energyos.espi.thirdparty.mocks.MockRestTemplate.java
@SuppressWarnings("unchecked") @Override//from www . j a va 2s.c om public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) throws RestClientException { ClassPathResource sourceFile = new ClassPathResource("/fixtures/test_usage_data.xml"); String inputStreamString; try { inputStreamString = new Scanner(sourceFile.getInputStream(), "UTF-8").useDelimiter("\\A").next(); return new ResponseEntity<>((T) inputStreamString, HttpStatus.OK); } catch (IOException e) { e.printStackTrace(); throw new RestClientException("The file import broke."); } }
From source file:com.appglu.android.sync.MockSyncOperations.java
protected InputStream jsonInputStream(String filename) throws IOException { ClassPathResource classPathResource = new ClassPathResource(filename + ".json", getClass()); return classPathResource.getInputStream(); }
From source file:pl.softech.eav.example.DocumentManagementService.java
private String readConfiguration(String filename) throws Exception { ClassPathResource rs = new ClassPathResource(filename); StringBuffer buffer = new StringBuffer(); try (InputStreamReader in = new InputStreamReader(rs.getInputStream())) { try (BufferedReader bin = new BufferedReader(in)) { String line;/*from w w w . j a v a2 s . co m*/ while ((line = bin.readLine()) != null) { buffer.append(line).append("\n"); } } } return buffer.toString(); }
From source file:cloudfoundry.norouter.f5.F5Initializer.java
ST routerIRule() throws IOException { final ClassPathResource resource = new ClassPathResource("templates/irules/router.tcl.st"); final String template = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8); return new ST(template, '`', '`'); }
From source file:cloudfoundry.norouter.f5.F5Initializer.java
ST loggingIRule() throws IOException { final ClassPathResource resource = new ClassPathResource("templates/irules/logging.tcl.st"); final String template = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8); return new ST(template, '`', '`'); }
From source file:org.openmrs.module.dhisreport.api.DHIS2ReportingServiceDAOTest.java
@Ignore @Test/* w w w .j a va 2 s . c om*/ public void unMarshallandSaveReportTemplates() throws Exception { ClassPathResource resource = new ClassPathResource("templates_ethiopia.xml"); service.unMarshallandSaveReportTemplates(resource.getInputStream()); }