List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:de.alpharogroup.duplicate.files.actions.ShowLicenseFrameAction.java
/** * Load license.//w w w. j av a 2 s . c om * * @return the string */ private String loadLicense() { ApplicationContext ctx = SpringApplicationContext.getInstance().getApplicationContext(); Resource resource = ctx.getResource("classpath:LICENSE.txt"); InputStream is = null; StringBuffer license = new StringBuffer(); try { String thisLine; is = resource.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); while ((thisLine = br.readLine()) != null) { license.append(thisLine + "\n"); } } catch (IOException ex) { ex.printStackTrace(); } finally { try { StreamExtensions.close(is); } catch (IOException e) { e.printStackTrace(); } } return license.toString(); }
From source file:org.alloy.metal.xml.merge.ImportProcessor.java
public List<ResourceInputStream> extract(List<ResourceInputStream> sources) throws MergeException { try {/*from w ww . j a v a 2 s . c o m*/ DynamicResourceIterator resourceList = new DynamicResourceIterator(); resourceList.addAll(sources); while (resourceList.hasNext()) { ResourceInputStream myStream = resourceList.nextResource(); Document doc = builder.parse(myStream); NodeList nodeList = (NodeList) xPath.evaluate(IMPORT_PATH, doc, XPathConstants.NODESET); int length = nodeList.getLength(); for (int j = 0; j < length; j++) { Element element = (Element) nodeList.item(j); Resource resource = loader.getResource(element.getAttribute("resource")); ResourceInputStream ris = new ResourceInputStream(resource.getInputStream(), resource.getURL().toString()); resourceList.addEmbeddedResource(ris); element.getParentNode().removeChild(element); } if (length > 0) { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer xmlTransformer = tFactory.newTransformer(); xmlTransformer.setOutputProperty(OutputKeys.VERSION, "1.0"); xmlTransformer.setOutputProperty(OutputKeys.ENCODING, _String.CHARACTER_ENCODING.toString()); xmlTransformer.setOutputProperty(OutputKeys.METHOD, "xml"); xmlTransformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(doc); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(baos)); StreamResult result = new StreamResult(writer); xmlTransformer.transform(source, result); byte[] itemArray = baos.toByteArray(); resourceList.set(resourceList.getPosition() - 1, new ResourceInputStream( new ByteArrayInputStream(itemArray), null, myStream.getNames())); } else { myStream.reset(); } } return resourceList; } catch (Exception e) { throw new MergeException(e); } }
From source file:org.jasig.portlet.maps.dao.GoogleMyMapsDaoImpl.java
@Value("${map.policy.file:classpath:/antisamy-textonly.xml}") public void setPolicy(Resource policyFile) throws PolicyException, IOException { this.policy = Policy.getInstance(policyFile.getInputStream()); }
From source file:fi.helsinki.opintoni.integration.oodi.mock.OodiMockClient.java
public <T> T getSingleOodiResponse(Resource resource, TypeReference<OodiSingleResponse<T>> typeReference) { try {/* w w w.j ava2 s. c o m*/ OodiSingleResponse<T> response = objectMapper.readValue(resource.getInputStream(), typeReference); return response.data; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:nz.co.senanque.parser.InputStreamParserSource.java
public InputStreamParserSource(Resource resource, int bufferSize) throws IOException { this(resource.getInputStream(), resource.getURI().toString(), bufferSize); }
From source file:org.obiba.mica.micaConfig.service.EntityConfigService.java
private String getResourceAsString(String path, String defaultValue) { if (StringUtils.isEmpty(path)) return defaultValue; Resource resource = new DefaultResourceLoader().getResource(path); try (Scanner s = new Scanner(resource.getInputStream())) { return s.useDelimiter("\\A").hasNext() ? s.next() : ""; } catch (IOException e) { return defaultValue; }//from ww w . j a va 2s . com }
From source file:org.springsource.tutorial.util.DBInitializer.java
/** * {@inheritDoc}/*from w w w. j a v a2s . co m*/ */ @Override public void afterPropertiesSet() throws Exception { Resource jsonResource = new ClassPathResource("usstates.json"); ObjectMapper mapper = new ObjectMapper(); TypeReference<List<USState>> ref = new TypeReference<List<USState>>() { }; List<USState> states = mapper.readValue(jsonResource.getInputStream(), ref); TransactionStatus status = tm.getTransaction(null); for (USState state : states) { state.persist(); } tm.commit(status); }
From source file:org.springmodules.jcr.jackrabbit.JackrabbitSessionFactory.java
protected void registerNodeTypes() throws Exception { if (!ObjectUtils.isEmpty(nodeDefinitions)) { Workspace ws = getSession().getWorkspace(); // Get the NodeTypeManager from the Workspace. // Note that it must be cast from the generic JCR NodeTypeManager to // the//from w w w . j a v a 2 s . co m // Jackrabbit-specific implementation. JackrabbitNodeTypeManager nodeTypeManager = (JackrabbitNodeTypeManager) ws.getNodeTypeManager(); boolean debug = log.isDebugEnabled(); for (int i = 0; i < nodeDefinitions.length; i++) { Resource resource = nodeDefinitions[i]; if (debug) log.debug("adding node type definitions from " + resource.getDescription()); nodeTypeManager.registerNodeTypes(resource.getInputStream(), contentType); } } }
From source file:org.jnap.core.assets.StaticAssetsHandler.java
public void handle() { try {/* ww w .j a va 2 s. co m*/ Resource[] resources = this.resourceResolver.getResources(source); if (destination != null) { Resource destRes = new ServletContextResource(servletContext, destination); resetResource(destRes); BufferedWriter writer = new BufferedWriter( new FileWriterWithEncoding(destRes.getFile(), this.encoding, true)); for (Resource resource : resources) { IOUtils.copy(resource.getInputStream(), writer); } IOUtils.closeQuietly(writer); resources = new Resource[1]; resources[0] = destRes; } for (Resource resource : resources) { // doHandle(resource); // File file = resource.getFile(); String digest = DigestUtils.shaHex(resource.getInputStream()); availableStaticAssets.put(resource.getFilename(), digest); if (compress) { Resource compressedResource = doCompression(resource); digest = DigestUtils.shaHex(compressedResource.getInputStream()); availableStaticAssets.put(compressedResource.getFilename(), digest); } } } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:com.epam.ta.reportportal.util.ResourceCopierBeanTest.java
@Test public void testResourceCopierBean() throws IOException { File createdFile = new File(StandardSystemProperty.JAVA_IO_TMPDIR.value(), RANDOM_NAME); Resource resource = resourceLoader.getResource(RESOURCE_TO_BE_COPIED); String copied = Files.toString(createdFile, Charsets.UTF_8); String fromResource = CharStreams .toString(new InputStreamReader(resource.getInputStream(), Charsets.UTF_8)); Assert.assertEquals("Copied file is not equal to resource source", fromResource, copied); }