List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:com.civilizer.web.handler.ResourceHttpRequestHandler.java
/** * Write the actual content out to the given servlet response, * streaming the resource's content./* w w w . j a va 2 s. c o m*/ * @param response current servlet response * @param resource the identified resource (never {@code null}) * @throws IOException in case of errors while writing the content */ protected void writeContent(HttpServletResponse response, Resource resource) throws IOException { StreamUtils.copy(resource.getInputStream(), response.getOutputStream()); }
From source file:com.teasoft.teavote.util.Signature.java
private PublicKey getPublicKey() throws IOException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException { Resource resource = res.getResource("classpath:gotaSafui"); byte[] pubKeyBytes; try (InputStream pubKeyInputStream = resource.getInputStream()) { pubKeyBytes = IOUtils.toByteArray(pubKeyInputStream); pubKeyBytes = Base64.decodeBase64(pubKeyBytes); }//ww w .j av a 2s.co m X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(pubKeyBytes); KeyFactory keyFactory = KeyFactory.getInstance("DSA", "SUN"); PublicKey pubKey = keyFactory.generatePublic(pubKeySpec); return pubKey; }
From source file:at.gv.egiz.bku.spring.ConfigurationFactoryBean.java
protected Configuration getDefaultConfiguration() throws ConfigurationException, IOException { Resource resource = resourceLoader.getResource(DEFAULT_CONFIG); XMLConfiguration xmlConfiguration = new XMLConfiguration(); xmlConfiguration.load(resource.getInputStream()); xmlConfiguration.setURL(resource.getURL()); return xmlConfiguration; }
From source file:org.carewebframework.ui.LabelFinder.java
/** * Validates entries in a label resource. * /*from w w w. ja v a 2s.c o m*/ * @param resource A label resource. */ private void validate(Resource resource) { InputStream is = null; try { Map<String, String> map = new HashMap<String, String>(); is = resource.getInputStream(); Maps.load(map, is); for (String key : map.keySet()) { for (String pc : key.split("\\.")) { if (!Validation.isIdentifier(pc)) { throw new RuntimeException("Label resource " + resource + " contains an invalid identifier: " + pc + " in " + key); } } } } catch (Exception e) { log.warn(e); } finally { IOUtils.closeQuietly(is); } }
From source file:com.teasoft.teavote.util.Signature.java
private PrivateKey getPrivateKey() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { Resource resource = res.getResource("classpath:xormeSafui"); byte[] privKeyBytes; try (InputStream privKeyInputStream = resource.getInputStream()) { privKeyBytes = IOUtils.toByteArray(privKeyInputStream); privKeyBytes = Base64.decodeBase64(privKeyBytes); }//from ww w. j a v a 2 s . c o m PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(privKeyBytes); KeyFactory keyFactory = KeyFactory.getInstance("DSA"); PrivateKey privKey = keyFactory.generatePrivate(privKeySpec); return privKey; }
From source file:net.javacrumbs.springws.test.common.MessageGenerator.java
public WebServiceMessage generateMessage(WebServiceMessageFactory messageFactory, Resource resource) throws IOException { if (shouldCreateSoapEnvelope(resource)) { WebServiceMessage message = messageFactory.createWebServiceMessage(); getXmlUtil().transform(new StreamSource(resource.getInputStream()), message.getPayloadResult()); logMessage(message);//from ww w. j a v a 2 s. c om return message; } else { WebServiceMessage message = messageFactory.createWebServiceMessage(createInputStream(resource)); logMessage(message); return message; } }
From source file:org.infinispan.spring.AbstractInfinispanRemoteCacheManagerBackedCacheManagerFactory.java
private Properties loadPropertiesFromFile(final Resource propertiesFileLocation) throws IOException { InputStream propsStream = null; try {/* www. j a v a2 s. com*/ propsStream = propertiesFileLocation.getInputStream(); final Properties answer = new Properties(); answer.load(propsStream); return answer; } finally { if (propsStream != null) { try { propsStream.close(); } catch (final IOException e) { this.logger.warn( "Failed to close InputStream used to load configuration properties: " + e.getMessage(), e); } } } }
From source file:org.solmix.runtime.cm.support.SpringConfigureUnitManager.java
protected Properties loadProperties(Resource location) { Properties props = new Properties(); InputStream is = null;// w ww . java 2 s . c o m try { is = location.getInputStream(); String filename = location.getFilename(); if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) { this.propertiesPersister.loadFromXml(props, is); } else { if (this.fileEncoding != null) { this.propertiesPersister.load(props, new InputStreamReader(is, this.fileEncoding)); } else { this.propertiesPersister.load(props, is); } } } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not load properties from " + location + ": " + ex.getMessage()); } } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } checkSystemProperties(props); return props; }
From source file:org.testng.spring.test.AbstractTransactionalDataSourceSpringContextTests.java
/** * Execute the given SQL script. Will be rolled back by default, * according to the fate of the current transaction. * @param sqlResourcePath Spring resource path for the SQL script. * Should normally be loaded by classpath. There should be one statement * per line. Any semicolons will be removed. * <b>Do not use this method to execute DDL if you expect rollback.</b> * @param continueOnError whether or not to continue without throwing * an exception in the event of an error * @throws DataAccessException if there is an error executing a statement * and continueOnError was false/* ww w .j ava 2s . c o m*/ */ protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException { if (logger.isInfoEnabled()) { logger.info("Executing SQL script '" + sqlResourcePath + "'"); } long startTime = System.currentTimeMillis(); List statements = new LinkedList(); Resource res = getApplicationContext().getResource(sqlResourcePath); try { LineNumberReader lnr = new LineNumberReader(new InputStreamReader(res.getInputStream())); String currentStatement = lnr.readLine(); while (currentStatement != null) { currentStatement = StringUtils.replace(currentStatement, ";", ""); statements.add(currentStatement); currentStatement = lnr.readLine(); } for (Iterator itr = statements.iterator(); itr.hasNext();) { String statement = (String) itr.next(); try { int rowsAffected = this.jdbcTemplate.update(statement); if (logger.isDebugEnabled()) { logger.debug(rowsAffected + " rows affected by SQL: " + statement); } } catch (DataAccessException ex) { if (continueOnError) { if (logger.isWarnEnabled()) { logger.warn("SQL: " + statement + " failed", ex); } } else { throw ex; } } } long elapsedTime = System.currentTimeMillis() - startTime; logger.info("Done executing SQL script '" + sqlResourcePath + "' in " + elapsedTime + " ms"); } catch (IOException ex) { throw new DataAccessResourceFailureException("Failed to open SQL script '" + sqlResourcePath + "'", ex); } }
From source file:se.inera.intyg.intygstjanst.web.service.bean.IntygBootstrapBean.java
private void addSjukfall(final Resource metadata, final Resource content) { try {//from w w w. ja v a2 s. c om Certificate certificate = new CustomObjectMapper().readValue(metadata.getInputStream(), Certificate.class); if (!isSjukfallsGrundandeIntyg(certificate.getType())) { return; } transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { try { Certificate certificate = new CustomObjectMapper().readValue(metadata.getInputStream(), Certificate.class); certificate.setDocument(IOUtils.toString(content.getInputStream(), "UTF-8")); ModuleApi moduleApi = moduleRegistry.getModuleApi(certificate.getType()); Utlatande utlatande = moduleApi.getUtlatandeFromJson(certificate.getDocument()); if (certificateToSjukfallCertificateConverter.isConvertableFk7263(utlatande)) { SjukfallCertificate sjukfallCertificate = certificateToSjukfallCertificateConverter .convertFk7263(certificate, utlatande); entityManager.persist(sjukfallCertificate); } } catch (Throwable t) { status.setRollbackOnly(); LOG.error("Loading of Sjukfall intyg failed for {}: {}", metadata.getFilename(), t.getMessage()); } } }); } catch (IOException e) { e.printStackTrace(); } }