List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:de.perdian.commons.lang.conversion.impl.converters.ResourceToCharSequenceConverter.java
@Override public CharSequence convert(Resource resource) { if (resource == null) { return null; } else {// w ww. j av a2 s . com try { try (InputStream resourceStream = resource.getInputStream()) { return IOUtils.toString(resourceStream, "UTF-8"); } } catch (IOException e) { throw new ConverterException(resource, "Cannot read data from Resource", e); } } }
From source file:org.zalando.stups.swagger.codegen.SwaggerCodegenController.java
@RequestMapping(value = "/v2/api-docs") public String getApi() throws IOException { final Resource r = resourceLoader.getResource(swaggerCodegenProperties.getApiClasspathLocation()); return new String(StreamUtils.copyToByteArray(r.getInputStream())); }
From source file:com.springcryptoutils.core.keystore.DefaultKeyStoreFactoryBean.java
public void afterPropertiesSet() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, InitializationException { final String keyStoreLocation = System.getProperty("javax.net.ssl.keyStore"); if (keyStoreLocation == null || keyStoreLocation.trim().length() == 0) { throw new InitializationException( "no value was specified for the system property: javax.net.ssl.keyStore"); }/*from w ww . j a v a 2 s . co m*/ final String password = System.getProperty("javax.net.ssl.keyStorePassword"); final Resource location = new FileSystemResource(keyStoreLocation); keystore = KeyStore.getInstance("JKS"); keystore.load(location.getInputStream(), password.toCharArray()); }
From source file:org.joverseer.ui.command.RestoreDefaultLayoutCommand.java
@Override protected void doExecuteCommand() { log.debug("Execute command"); DockingManager manager = ((JideApplicationWindow) getApplicationWindow()).getDockingManager(); Resource r = Application.instance().getApplicationContext().getResource("classpath:layout/default.layout"); try {//from ww w . ja v a 2 s. c o m manager.loadLayoutFrom(r.getInputStream()); } catch (Exception exc) { log.error("Failed to load original layout from layout file " + exc.getMessage()); } }
From source file:cherry.example.web.validation.ex40.ValidationEx40ControllerImpl.java
private <T> T readValue(Resource resource, TypeReference<T> typeRef) { try (InputStream in = resource.getInputStream()) { return objectMapper.readValue(in, typeRef); } catch (IOException ex) { throw new IllegalStateException(ex); }//from w ww . j a va 2 s . com }
From source file:com.opengamma.component.ComponentConfigLoader.java
/** * Reads lines from the resource./*from w ww . j a v a 2 s . co m*/ * * @param resource the resource to read, not null * @return the lines, not null */ private List<String> readLines(Resource resource) { try { return IOUtils.readLines(resource.getInputStream(), "UTF8"); } catch (IOException ex) { throw new OpenGammaRuntimeException("Unable to read resource: " + resource, ex); } }
From source file:com.onyxscheduler.domain.HttpJobJsonSerializationIT.java
private Job loadJobFromJsonFile(Resource file) throws IOException { return converter.getObjectMapper().readValue(file.getInputStream(), Job.class); }
From source file:net.sf.gazpachoquest.test.dbunit.support.ColumnDetectorXmlDataSetLoader.java
@Override protected IDataSet createDataSet(Resource resource) throws Exception { FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder(); builder.setColumnSensing(true);/*from w ww. j a v a2s .co m*/ InputStream inputStream = resource.getInputStream(); try { return builder.build(inputStream); } finally { inputStream.close(); } }
From source file:com.thinkbiganalytics.spring.FileResourceService.java
public String resourceAsString(Resource resource) { try {/*www.j av a 2 s . c o m*/ if (resource != null) { InputStream is = resource.getInputStream(); return IOUtils.toString(is, Charset.defaultCharset()); } } catch (IOException e) { log.error("Unable to load file {} ", resource.getFilename(), e); } return null; }
From source file:gov.nih.nci.cabig.caaers2adeers.xslt.ClasspathURIResolver.java
public Source resolve(String href, String base) throws TransformerException { if (log.isDebugEnabled()) log.debug(//from w w w .j av a2 s .c om "resolving (" + baseFolder + href + ") the resource [base : " + base + ", href :" + href + "]"); try { Resource resource = resourceLoader.getResource(baseFolder + href); if (resource != null && resource.exists()) return new StreamSource(resource.getInputStream()); } catch (Exception e) { log.error("Unable to load resource [base : " + base + ", href: " + href + "]", e); } if (log.isDebugEnabled()) log.debug("unable to find resource [base : " + base + ", href :" + href + "], " + "so instructing to use default lookup"); return null; //use default lookup }