List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:org.globus.security.stores.CertKeyCredential.java
protected X509Credential createObject(Resource certSource, Resource keySource) throws ResourceStoreException { InputStream certIns;/*from w w w . ja v a 2 s . c o m*/ InputStream keyIns; try { certIns = certSource.getInputStream(); keyIns = keySource.getInputStream(); return new X509Credential(certIns, keyIns); } catch (FileNotFoundException e) { throw new ResourceStoreException(e); } catch (CredentialException e) { throw new ResourceStoreException(e); } catch (IOException ioe) { throw new ResourceStoreException(ioe); } }
From source file:com.qcadoo.view.internal.resource.module.UniversalResourceModule.java
@Override public boolean serveResource(final HttpServletRequest request, final HttpServletResponse response) { Resource resource = getResourceFromURI(request.getRequestURI()); if (resource != null && resource.exists()) { response.setContentType(getContentTypeFromURI(request)); try {// w w w . j av a 2s.c om IOUtils.copy(resource.getInputStream(), response.getOutputStream()); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } return true; } else { return false; } }
From source file:org.cloudfoundry.reconfiguration.util.StandardCloudUtils.java
private Set<String> getCloudServiceClasses(Resource resource) { Set<String> cloudServiceClasses = new HashSet<String>(); BufferedReader in = null;//from ww w . ja v a 2s . co m try { in = new BufferedReader(new InputStreamReader(resource.getInputStream())); String line; while ((line = in.readLine()) != null) { cloudServiceClasses.add(line.trim()); } } catch (IOException e) { this.logger .warning(String.format("Unable to read cloud service classes from %s", resource.getFilename())); } finally { IoUtils.closeQuietly(in); } return cloudServiceClasses; }
From source file:net.sourceforge.vulcan.spring.SpringProjectDomBuilder.java
@Override protected Transformer createTransformer(String format) throws NoSuchTransformFormatException { if (!transformResources.containsKey(format)) { throw new NoSuchTransformFormatException(); }/*from w w w .j ava2s . co m*/ final Resource resource = applicationContext.getResource(transformResources.get(format)); try { final SAXSource source = new SAXSource(XMLReaderFactory.createXMLReader(), new InputSource(resource.getInputStream())); try { // Try to tell the xsl where it is for the sake of xsl:include source.setSystemId(resource.getFile().getAbsolutePath()); } catch (FileNotFoundException ignore) { // Not all resources are backed by files. } return transformerFactory.newTransformer(source); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RuntimeException(e); } }
From source file:se.ivankrizsan.messagecowboy.services.transport.AbstractXmlConfigurerdTransportService.java
/** * Retrieves configuration resource information for the currently configured * XML configuration resources./*from www . j a v a2s . c o m*/ * * @return List of configuration resource information. * @throws IOException If error occurs discovering or accessing configuration resource. */ protected List<XmlConfigurationResourceInfo> retrieveXmlConfigResourceInfos() throws IOException { final PathMatchingResourcePatternResolver theConnectorsResolver = new PathMatchingResourcePatternResolver(); final List<XmlConfigurationResourceInfo> theConfigRsrcInfos = new ArrayList<XmlConfigurationResourceInfo>(); for (String theConfigRsrcsLocationPattern : mConfigResourcesLocationPatterns) { final Resource[] theConnectorsConfigurations = theConnectorsResolver .getResources(theConfigRsrcsLocationPattern); LOGGER.debug("Found {} connector configuration files using the pattern {}", theConnectorsConfigurations.length, theConfigRsrcsLocationPattern); if (theConnectorsConfigurations.length > 0) { for (Resource theResource : theConnectorsConfigurations) { final byte[] theConfigRsrcContents = FileCopyUtils .copyToByteArray(theResource.getInputStream()); final String theConfigRsrcName = theResource.getFilename(); final String theConfigRsrcChecksum = DigestUtils.md5Hex(theConfigRsrcContents); final XmlConfigurationResourceInfo theConfigRsrcInfo = new XmlConfigurationResourceInfo( theConfigRsrcName, theConfigRsrcChecksum); theConfigRsrcInfos.add(theConfigRsrcInfo); } } } return theConfigRsrcInfos; }
From source file:org.mongeez.reader.XmlChangeSetReader.java
@Override public List<ChangeSet> getChangeSets(Resource file) { List<ChangeSet> changeSets = new ArrayList<ChangeSet>(); try {/*ww w . j a v a 2s . c o m*/ logger.info("Parsing XML Change Set File {}", file.getFilename()); ChangeSetList changeFileSet = (ChangeSetList) digester.parse(file.getInputStream()); if (changeFileSet == null) { logger.warn("Ignoring change file {}, the parser returned null. Please check your formatting.", file.getFilename()); } else { for (ChangeSet changeSet : changeFileSet.getList()) { ChangeSetReaderUtil.populateChangeSetResourceInfo(changeSet, file); } changeSets.addAll(changeFileSet.getList()); } } catch (IOException e) { logger.error("IOException", e); } catch (org.xml.sax.SAXException e) { logger.error("SAXException", e); } return changeSets; }
From source file:org.beanio.spring.BeanIOStreamFactory.java
/** * Creates a new {@link StreamFactory} and loads configured stream mapping resources. * @return the new <tt>StreamFactory</tt> * @throws BeanIOConfigurationException if a stream mapping resource does not exist * or is invalid /* ww w . ja va2 s . c om*/ * @throws IOException if an I/O error occurs */ protected StreamFactory createStreamFactory() throws IOException, BeanIOConfigurationException { StreamFactory factory = StreamFactory.newInstance(); if (streamMappings != null) { for (Resource res : streamMappings) { if (!res.exists()) { throw new BeanIOConfigurationException("Mapping file not found: " + res); } InputStream in = res.getInputStream(); try { factory.load(in); } catch (BeanIOConfigurationException ex) { throw new BeanIOConfigurationException( "Error in mapping file '" + res + "': " + ex.getMessage(), ex); } finally { IOUtil.closeQuietly(in); } } } return factory; }
From source file:org.data.support.beans.factory.xml.SchemaResolver.java
public InputSource resolveEntity(String publicId, String systemId) throws IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public id [" + publicId + "] and system id [" + systemId + "]"); }//from ww w . j ava 2 s . com if (systemId != null) { String resourceLocation = getSchemaMappings().get(systemId); if (resourceLocation != null) { Resource resource = new ClassPathResource(resourceLocation, this.classLoader); try { InputSource source = new InputSource(resource.getInputStream()); source.setPublicId(publicId); source.setSystemId(systemId); if (logger.isDebugEnabled()) { logger.debug("Found XML schema [" + systemId + "] in classpath: " + resourceLocation); } return source; } catch (FileNotFoundException ex) { if (logger.isDebugEnabled()) { logger.debug("Couldn't find XML schema [" + systemId + "]: " + resource, ex); } } } } return null; }
From source file:org.jasig.schedassist.model.ICalendarDataTest.java
@Test public void testParseCalendarDataWithRDate() throws IOException, ParserException { Resource exampleData = new ClassPathResource("org/jasig/schedassist/model/example-reflection.ics"); CalendarBuilder builder = new CalendarBuilder(); Calendar result = builder.build(new InputStreamReader(exampleData.getInputStream())); Assert.assertNotNull(result);//from ww w.j av a 2 s .c om ComponentList components = result.getComponents(VEvent.VEVENT); Assert.assertEquals(1, components.size()); VEvent event = (VEvent) components.get(0); PropertyList rdates = event.getProperties(RDate.RDATE); Assert.assertEquals(5, rdates.size()); Set<String> rdateValues = new HashSet<String>(); for (Object o : rdates) { Property rdate = (Property) o; Assert.assertEquals(net.fortuna.ical4j.model.parameter.Value.DATE, rdate.getParameter(net.fortuna.ical4j.model.parameter.Value.VALUE)); rdateValues.add(rdate.getValue()); } Assert.assertTrue(rdateValues.contains("20110921")); Assert.assertTrue(rdateValues.contains("20110923")); Assert.assertTrue(rdateValues.contains("20110926")); Assert.assertTrue(rdateValues.contains("20110928")); Assert.assertTrue(rdateValues.contains("20110930")); }
From source file:org.xacml4j.spring.repository.InMemoryPolicyRepositoryFactoryBean.java
@Override protected PolicyRepository createInstance() throws Exception { FunctionProviderBuilder functionProviderBuilder = FunctionProviderBuilder.builder().defaultFunctions(); if (extensionFunctions != null) { functionProviderBuilder.provider(extensionFunctions); }/*from ww w . j a v a 2 s .c o m*/ DecisionCombiningAlgorithmProviderBuilder decisionAlgorithmProviderBuilder = DecisionCombiningAlgorithmProviderBuilder .builder().withDefaultAlgorithms(); if (extensionDecisionCombiningAlgorithms != null) { decisionAlgorithmProviderBuilder.withAlgorithmProvider(extensionDecisionCombiningAlgorithms); } Preconditions.checkState(resources != null, "Policy resources must be specified"); InMemoryPolicyRepository repository = new InMemoryPolicyRepository(id, functionProviderBuilder.build(), decisionAlgorithmProviderBuilder.create()); for (final Resource r : resources) { repository.importPolicy(new Supplier<InputStream>() { @Override public InputStream get() { try { return r.getInputStream(); } catch (IOException e) { throw new IllegalArgumentException( String.format("Could not import policy from resource \"%s\"", r), e); } } }); } return repository; }