List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:com.kudian.common.utils.PropertiesLoader.java
/** * , Spring Resource?./* ww w . j a v a 2s .c o m*/ */ private Properties loadProperties(String... resourcesPaths) { Properties props = new Properties(); for (String location : resourcesPaths) { //logger.debug("Loading properties file from:" + location); InputStream is = null; try { Resource resource = resourceLoader.getResource(location); is = resource.getInputStream(); props.load(is); } catch (IOException ex) { logger.info("Could not load properties from path:" + location + ", " + ex.getMessage()); } finally { IOUtils.closeQuietly(is); } } return props; }
From source file:com.lejingw.app.myact.util.PropertiesLoader.java
/** * , Spring Resource?.//from w w w . ja v a2s . com */ private Properties loadProperties(String... resourcesPaths) { Properties props = new Properties(); for (String location : resourcesPaths) { logger.debug("Loading properties file from:" + location); InputStream is = null; try { Resource resource = resourceLoader.getResource(location); is = resource.getInputStream(); props.load(is); } catch (IOException ex) { logger.info("Could not load properties from path:" + location + ", " + ex.getMessage()); } finally { IOUtils.closeQuietly(is); } } return props; }
From source file:org.data.support.beans.factory.xml.QueryDTDResolver.java
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public ID [" + publicId + "] and system ID [" + systemId + "]"); }/* ww w . j a va2s .c o m*/ if (systemId != null && systemId.endsWith(DTD_EXTENSION)) { int lastPathSeparator = systemId.lastIndexOf("/"); for (String DTD_NAME : DTD_NAMES) { int dtdNameStart = systemId.indexOf(DTD_NAME); if (dtdNameStart > lastPathSeparator) { String dtdFile = systemId.substring(dtdNameStart); if (logger.isTraceEnabled()) { logger.trace("Trying to locate [" + dtdFile + "] in Spring jar"); } try { Resource resource = new ClassPathResource(dtdFile, getClass()); InputSource source = new InputSource(resource.getInputStream()); source.setPublicId(publicId); source.setSystemId(systemId); if (logger.isDebugEnabled()) { logger.debug("Found queries DTD [" + systemId + "] in classpath: " + dtdFile); } return source; } catch (IOException ex) { if (logger.isDebugEnabled()) { logger.debug( "Could not resolve queries DTD [" + systemId + "]: not found in class path", ex); } } } } } // Use the default behavior -> download from website or wherever. return null; }
From source file:org.solmix.runtime.support.spring.SpringResourceResolver.java
@Override public <T> T resolve(String resourceName, Class<T> resourceType) { try {//from w ww . jav a 2 s. c o m T resource = null; if (resourceName == null) { String names[] = context.getBeanNamesForType(resourceType); if (names != null && names.length > 0) { resource = resourceType.cast(context.getBean(names[0], resourceType)); } } else { resource = resourceType.cast(context.getBean(resourceName, resourceType)); } return resource; } catch (NoSuchBeanDefinitionException def) { //ignore } try { if (ClassLoader.class.isAssignableFrom(resourceType)) { return resourceType.cast(context.getClassLoader()); } else if (URL.class.isAssignableFrom(resourceType)) { Resource r = context.getResource(resourceName); if (r != null && r.exists()) { r.getInputStream().close(); //checks to see if the URL really can resolve return resourceType.cast(r.getURL()); } } } catch (IOException e) { //ignore } return null; }
From source file:com.fns.grivet.service.NamedQueryServiceSprocTest.java
@Test public void testNamedQueryNotExecutedBecauseParamSuppliedForExecutionNotCorrectlyNamed() throws IOException { Assertions.assertThrows(IllegalArgumentException.class, () -> { Resource r = resolver.getResource("classpath:TestSprocQuery.json"); String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset()); NamedQuery namedQuery = objectMapper.readValue(json, NamedQuery.class); namedQueryService.create(namedQuery); MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1)); params.add("timeCreated", tomorrow); namedQueryService.get("sproc.getAttributesCreatedBefore", params); });/*www .j a v a2 s . c o m*/ }
From source file:com.yahoo.bard.webservice.config.ConfigResourceLoader.java
/** * Build a configuration object from a resource, processing it as a properties file. * * @param resource The resource referring to a properties file * * @return a Configuration object containing a properties configuration *//*from w w w . j a va 2 s . c o m*/ public Configuration loadConfigFromResource(Resource resource) { PropertiesConfiguration result = new PropertiesConfiguration(); try { result.load(resource.getInputStream()); return result; } catch (ConfigurationException | IOException e) { LOG.error(CONFIGURATION_LOAD_ERROR.format(resource.getFilename()), e); throw new SystemConfigException(CONFIGURATION_LOAD_ERROR.format(resource.getFilename()), e); } }
From source file:org.fenixedu.start.service.ProjectService.java
private Map<String, byte[]> build(ProjectRequest request, String type) throws PebbleException, IOException { List<Resource> resources = resourcesByType.get(type); Map<String, byte[]> project = new HashMap<>(); for (Resource resource : resources) { if (resource.isReadable()) { String fileData = process(new String(ByteStreams.toByteArray(resource.getInputStream())), request); if (fileData != null) { String filePath = getFilePath(resource, type); project.put(process(filePath, request), fileData.getBytes()); }/*from w w w .j a va2 s . c o m*/ } } return project; }
From source file:org.globus.security.stores.ResourceTrustAnchor.java
@Override protected TrustAnchor create(Resource resource) throws ResourceStoreException { X509Certificate certificate;//from w ww.ja v a 2 s .c o m try { certificate = CertificateLoadUtil.loadCertificate(resource.getInputStream()); } catch (IOException e) { throw new ResourceStoreException(e); } catch (GeneralSecurityException e) { throw new ResourceStoreException(e); } return new TrustAnchor(certificate, null); }
From source file:$.PropertiesLoader.java
/** * , Spring Resource?.//from ww w.j av a 2 s . c o m */ private Properties loadProperties(String... resourcesPaths) { Properties props = new Properties(); for (String location : resourcesPaths) { logger.debug("Loading properties file from path:{}", location); InputStream is = null; try { Resource resource = resourceLoader.getResource(location); is = resource.getInputStream(); props.load(is); } catch (IOException ex) { logger.info("Could not load properties from path:{}, {} ", location, ex.getMessage()); } finally { IOUtils.closeQuietly(is); } } return props; }
From source file:com.opengamma.integration.server.copier.ServerDatabaseCreator.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); }// w w w.j av a2 s .com props.load(in); } // create main database s_logger.info("Creating main database..."); DbTool dbTool = new DbTool(); dbTool.setJdbcUrl(Objects.requireNonNull(props.getProperty(KEY_SHARED_URL))); dbTool.setUser(props.getProperty(KEY_SHARED_USER_NAME, "")); dbTool.setPassword(props.getProperty(KEY_SHARED_PASSWORD, "")); dbTool.setCatalog(CATALOG); // ignored, as it is parsed from the url dbTool.setCreate(true); dbTool.setDrop(true); dbTool.setCreateTables(true); dbTool.execute(); // create user database s_logger.info("Creating user database..."); DbTool dbToolUser = new DbTool(); dbToolUser.setJdbcUrl(Objects.requireNonNull(props.getProperty(KEY_USERFINANCIAL_URL))); dbToolUser.setUser(props.getProperty(KEY_USERFINANCIAL_USER_NAME, "")); dbToolUser.setPassword(props.getProperty(KEY_USERFINANCIAL_PASSWORD, "")); dbToolUser.setCatalog(CATALOG); // ignored, as it is parsed from the url dbToolUser.setCreate(true); dbToolUser.setDrop(true); dbToolUser.setCreateTables(true); dbToolUser.execute(); // populate the database s_logger.info("Populating main database..."); ServerDatabasePopulator populator = new ServerDatabasePopulator(_configFile, new DatabasePopulatorTool(_serverUrl)); populator.run(); s_logger.info("Successfully created server databases"); }