List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:org.globus.security.stores.ResourceSigningPolicy.java
public Map<X500Principal, SigningPolicy> create(Resource signingPolicyResource) throws ResourceStoreException { SigningPolicyFileParser parser = new SigningPolicyFileParser(); Map<X500Principal, SigningPolicy> policies; try {/* w ww.ja v a 2s . c om*/ policies = parser.parse(new InputStreamReader(signingPolicyResource.getInputStream())); } catch (IOException e) { throw new ResourceStoreException(e); } catch (SigningPolicyException e) { throw new ResourceStoreException(e); } return policies; }
From source file:be.solidx.hot.spring.config.DataConfig.java
@Bean public Map<be.solidx.hot.spring.config.HotConfig.DataSource, DataSource> dataSources() throws Exception { Map<be.solidx.hot.spring.config.HotConfig.DataSource, DataSource> dataSources = new HashMap<be.solidx.hot.spring.config.HotConfig.DataSource, DataSource>(); for (be.solidx.hot.spring.config.HotConfig.DataSource dataSource : hotConfig.getDataSources()) { switch (dataSource.getEngine()) { case ORACLE: dataSources.put(dataSource,//www. ja va2 s .c om oracleSimpleDriverDataSource(dataSource.getHostname(), dataSource.getPort(), dataSource.getDatabase(), dataSource.getUsername(), dataSource.getPassword())); break; case DB2: dataSources.put(dataSource, db2SimpleDriverDataSource(dataSource.getHostname(), dataSource.getPort(), dataSource.getDatabase(), dataSource.getUsername(), dataSource.getPassword())); break; case MYSQL: dataSources.put(dataSource, mysqlSimpleDriverDataSource(dataSource.getHostname(), dataSource.getPort(), dataSource.getDatabase(), dataSource.getUsername(), dataSource.getPassword())); break; case PGSQL: dataSources.put(dataSource, pgsqlSimpleDriverDataSource(dataSource.getHostname(), dataSource.getPort(), dataSource.getDatabase(), dataSource.getUsername(), dataSource.getPassword())); break; case HSQLDB: DataSource sqlDataSource = hsqldbSimpleDriverDataSource(dataSource.getDatabase(), dataSource.getUsername(), dataSource.getPassword()); try { JdbcTemplate jdbcTemplate = new JdbcTemplate(sqlDataSource); jdbcTemplate.afterPropertiesSet(); for (Resource resource : applicationContext.getResources("classpath*:/sql/*-init.sql")) { String[] statements = IOUtils.toString(resource.getInputStream()).split(";"); jdbcTemplate.batchUpdate(statements); } } catch (Exception e) { logger.error("", e); } dataSources.put(dataSource, sqlDataSource); break; default: break; } } return dataSources; }
From source file:com.glaf.core.db.mybatis2.SqlMapClientFactoryBean.java
/** * Build a SqlMapClient instance based on the given standard configuration. * <p>//from w w w . ja va 2s.c om * The default implementation uses the standard iBATIS * {@link SqlMapClientBuilder} API to build a SqlMapClient instance based on * an InputStream (if possible, on iBATIS 2.3 and higher) or on a Reader (on * iBATIS up to version 2.2). * * @param configLocations * the config files to load from * @param properties * the SqlMapClient properties (if any) * @return the SqlMapClient instance (never {@code null}) * @throws IOException * if loading the config file failed * @see com.ibatis.sqlmap.client.SqlMapClientBuilder#buildSqlMapClient */ protected SqlMapClient buildSqlMapClient(Resource[] configLocations, Resource[] mappingLocations, Properties properties) throws IOException { if (ObjectUtils.isEmpty(configLocations)) { throw new IllegalArgumentException("At least 1 'configLocation' entry is required"); } SqlMapClient client = null; SqlMapConfigParser configParser = new SqlMapConfigParser(); for (Resource configLocation : configLocations) { InputStream is = configLocation.getInputStream(); try { client = configParser.parse(is, properties); } catch (RuntimeException ex) { throw new NestedIOException("Failed to parse config resource: " + configLocation, ex.getCause()); } } if (mappingLocations != null) { SqlMapParser mapParser = SqlMapParserFactory.createSqlMapParser(configParser); for (Resource mappingLocation : mappingLocations) { try { mapParser.parse(mappingLocation.getInputStream()); } catch (NodeletException ex) { throw new NestedIOException("Failed to parse mapping resource: " + mappingLocation, ex); } } } return client; }
From source file:com.hp.application.automation.tools.octane.tests.CopyResourceSCM.java
@Override public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspace, BuildListener listener, File changeLogFile) throws IOException, InterruptedException { if (workspace.exists()) { listener.getLogger().println("Deleting existing workspace " + workspace.getRemote()); workspace.deleteRecursive();//w w w . ja v a2s . co m } Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath*:" + path + "/**"); for (Resource resource : resources) { if (resource.exists() && resource.isReadable()) { String urlString = resource.getURL().toExternalForm(); String targetName = urlString.substring(urlString.indexOf(path) + path.length()); byte[] fileContent = IOUtils.toByteArray(resource.getInputStream()); FileUtils.writeByteArrayToFile(new File(new File(workspace.getRemote(), targetPath), targetName), fileContent); } } return true; }
From source file:org.jasig.portlet.proxy.service.ClasspathResourceContentService.java
@Override public GenericContentResponseImpl getContent(final GenericContentRequestImpl proxyRequest, final PortletRequest request) { // get the resource corresponding to the configured location final Resource resource = new ClassPathResource(proxyRequest.getProxiedLocation()); try {/*from w w w .j a v a2 s . c om*/ // construct a content response using this resource final GenericContentResponseImpl proxyResponse = new GenericContentResponseImpl( proxyRequest.getProxiedLocation(), resource.getInputStream()); return proxyResponse; } catch (IOException e) { log.error("IOException retrieving resource {}", proxyRequest.getProxiedLocation()); } return null; }
From source file:com.github.dactiv.fear.service.service.message.MessageService.java
/** * spring ??????./*from w w w. ja v a2 s . c om*/ * @throws Exception */ @Override public void afterPropertiesSet() throws Exception { for (Resource r : resources) { JavaMailSenderImpl jms = new JavaMailSenderImpl(); Properties properties = new Properties(); properties.load(r.getInputStream()); jms.setUsername(properties.getProperty("mail.username")); jms.setPassword(properties.getProperty("mail.password")); jms.setHost(properties.getProperty("mail.host")); jms.setDefaultEncoding(properties.getProperty("mail.default.encoding", DEFAULT_MAIL_ENCODING)); jms.setJavaMailProperties(properties); javaMailSenders.add(jms); } }
From source file:com.vilt.minium.script.test.impl.MiniumRhinoTestsSupport.java
protected Object getVal(MiniumRhinoTestContextManager contextManager, JsVariable jsVariable, Class<?> clazz, Object object) {//from ww w . jav a 2 s . c o m try { Resource resource = getResource(contextManager, jsVariable); if (resource != null) { if (clazz == String.class) { InputStream is = resource.getInputStream(); try { return IOUtils.toString(is, Charsets.UTF_8.name()); } finally { IOUtils.closeQuietly(is); } } else { Object val = parseJson(cx, scope, resource); checkState(clazz.isAssignableFrom(val.getClass())); return val; } } else { return object; } } catch (IOException e) { throw propagate(e); } catch (ParseException e) { throw propagate(e); } }
From source file:org.cmo.cancerhotspots.controller.HotspotController.java
public InputStreamResource downloadFile(@PathVariable String filename) throws IOException { Resource resource = new ClassPathResource("data/" + filename + ".txt"); return new InputStreamResource(resource.getInputStream()); }
From source file:com.haulmont.cuba.core.sys.persistence.PersistenceConfigProcessor.java
private Document getDocument(String fileName) { Document doc;/* www . j av a2 s . co m*/ if (baseDir == null) { Resource resource = new ConfigurationResourceLoader().getResource(fileName); InputStream stream = null; try { stream = resource.getInputStream(); doc = Dom4j.readDocument(stream); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); } } else { if (!fileName.startsWith("/")) fileName = "/" + fileName; File file = new File(baseDir, fileName); if (!file.exists()) throw new IllegalArgumentException("File not found: " + file.getAbsolutePath()); doc = Dom4j.readDocument(file); } return doc; }
From source file:org.jasig.schedassist.impl.relationship.CSVRelationshipDataSourceImpl.java
/** * Read the {@link Resource} argument as a CSV file and extract a {@link List} * of {@link CSVRelationship}s./*from www. j a v a2 s .c om*/ * * @see CSVReader * @param resource * @return a never null, but potentially empty list of {@link CSVRelationship}s. */ protected List<CSVRelationship> readCSVResource(final Resource resource) throws IOException { Set<CSVRelationship> results = new HashSet<CSVRelationship>(); CSVReader lineReader = new CSVReader(new InputStreamReader(resource.getInputStream())); String[] tokens = lineReader.readNext(); while (null != tokens) { if (tokens.length == 3) { CSVRelationship relationship = new CSVRelationship(); relationship.setOwnerIdentifier(tokens[0]); relationship.setVisitorIdentifier(tokens[1]); relationship.setRelationshipDescription(tokens[2]); results.add(relationship); } else { LOG.debug("skipping CSV line with tokens.length != 3, " + Arrays.toString(tokens)); } tokens = lineReader.readNext(); } return new ArrayList<CSVRelationship>(results); }