List of usage examples for org.springframework.core.io Resource getDescription
String getDescription();
From source file:org.opennms.reporting.availability.render.HTMLReportRenderer.java
/** {@inheritDoc} */ @Override/*from ww w. j a v a 2 s . c om*/ public void render(final InputStream inputStream, final OutputStream outputStream, final Resource xsltResource) throws ReportRenderException { try { Logging.withPrefix(LOG4J_CATEGORY, new Callable<Void>() { @Override public Void call() throws Exception { LOG.debug("Rendering InputStream with XSL File {} to OutputStream", xsltResource.getDescription()); FileInputStream xslt = null; Reader xsl = null; Reader xml = null; try { xslt = new FileInputStream(xsltResource.getFile()); xsl = new InputStreamReader(xslt, "UTF-8"); xml = new InputStreamReader(inputStream, "UTF-8"); render(xml, outputStream, xsl); return null; } finally { IOUtils.closeQuietly(xml); IOUtils.closeQuietly(xsl); IOUtils.closeQuietly(xslt); } } }); } catch (final Exception e) { if (e instanceof ReportRenderException) throw (ReportRenderException) e; throw new ReportRenderException(e); } }
From source file:org.opennms.reporting.availability.render.HTMLReportRenderer.java
/** {@inheritDoc} */ @Override//from ww w. j ava 2s . c o m public void render(final String inputFileName, final String outputFileName, final Resource xsltResource) throws ReportRenderException { try { Logging.withPrefix(LOG4J_CATEGORY, new Callable<Void>() { @Override public Void call() throws Exception { LOG.debug("Rendering {} with XSL File {} to {} with base directory of {}", m_baseDir, inputFileName, xsltResource.getDescription(), outputFileName); FileInputStream in = null, xslt = null; FileOutputStream out = null; Reader xsl = null, xml = null; try { xslt = new FileInputStream(xsltResource.getFile()); xsl = new InputStreamReader(xslt, "UTF-8"); in = new FileInputStream(m_baseDir + "/" + inputFileName); xml = new InputStreamReader(in, "UTF-8"); out = new FileOutputStream(new File(m_baseDir + "/" + outputFileName)); render(xml, out, xsl); return null; } finally { IOUtils.closeQuietly(xml); IOUtils.closeQuietly(xsl); IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); IOUtils.closeQuietly(xslt); } } }); } catch (final Exception e) { if (e instanceof ReportRenderException) throw (ReportRenderException) e; throw new ReportRenderException(e); } }
From source file:org.opennms.reporting.availability.render.PDFReportRenderer.java
/** {@inheritDoc} */ @Override// w ww . j a v a 2 s . c om public byte[] render(final String inputFileName, final Resource xsltResource) throws ReportRenderException { try { return Logging.withPrefix(LOG4J_CATEGORY, new Callable<byte[]>() { @Override public byte[] call() throws Exception { LOG.debug("Rendering {} with XSL File {} to byte array", inputFileName, xsltResource.getDescription()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); render(inputFileName, outputStream, xsltResource); return outputStream.toByteArray(); } }); } catch (final Exception e) { if (e instanceof ReportRenderException) throw (ReportRenderException) e; throw new ReportRenderException(e); } }
From source file:org.opennms.reporting.availability.render.PDFReportRenderer.java
/** {@inheritDoc} */ @Override// www . j a v a 2 s . c o m public void render(final String inputFileName, final OutputStream outputStream, final Resource xsltResource) throws ReportRenderException { try { Logging.withPrefix(LOG4J_CATEGORY, new Callable<Void>() { @Override public Void call() throws Exception { FileInputStream in = null, xslt = null; Reader xsl = null, xml = null; try { LOG.debug("Rendering {} with XSL File {} to OutputStream", inputFileName, xsltResource.getDescription()); in = new FileInputStream(xsltResource.getFile()); xsl = new InputStreamReader(in, "UTF-8"); xslt = new FileInputStream(inputFileName); xml = new InputStreamReader(xslt, "UTF-8"); render(xml, outputStream, xsl); return null; } finally { IOUtils.closeQuietly(xml); IOUtils.closeQuietly(xslt); IOUtils.closeQuietly(xsl); IOUtils.closeQuietly(in); } } }); } catch (final Exception e) { if (e instanceof ReportRenderException) throw (ReportRenderException) e; throw new ReportRenderException(e); } }
From source file:org.opennms.reporting.availability.render.PDFReportRenderer.java
/** {@inheritDoc} */ @Override//from w w w. j av a 2 s. co m public void render(final InputStream inputStream, final OutputStream outputStream, final Resource xsltResource) throws ReportRenderException { try { Logging.withPrefix(LOG4J_CATEGORY, new Callable<Void>() { @Override public Void call() throws Exception { LOG.debug("Rendering InputStream with XSL File {} to OutputStream", xsltResource.getDescription()); FileInputStream xslt = null; Reader xsl = null, xml = null; try { xslt = new FileInputStream(xsltResource.getFile()); xsl = new InputStreamReader(xslt, "UTF-8"); xml = new InputStreamReader(inputStream, "UTF-8"); render(xml, outputStream, xsl); return null; } finally { IOUtils.closeQuietly(xml); } } }); } catch (final Exception e) { if (e instanceof ReportRenderException) throw (ReportRenderException) e; throw new ReportRenderException(e); } }
From source file:org.opennms.reporting.availability.render.PDFReportRenderer.java
/** {@inheritDoc} */ @Override//from ww w . j a v a 2 s . c o m public void render(final String inputFileName, final String outputFileName, final Resource xsltResource) throws ReportRenderException { try { Logging.withPrefix(LOG4J_CATEGORY, new Callable<Void>() { @Override public Void call() throws Exception { LOG.debug("Rendering {} with XSL File {} to {} with base directory of {}", m_baseDir, inputFileName, xsltResource.getDescription(), outputFileName); FileInputStream in = null, xslt = null; FileOutputStream out = null; Reader xsl = null, xml = null; try { xslt = new FileInputStream(xsltResource.getFile()); xsl = new InputStreamReader(xslt, "UTF-8"); in = new FileInputStream(m_baseDir + "/" + inputFileName); xml = new InputStreamReader(in, "UTF-8"); out = new FileOutputStream(new File(m_baseDir + "/" + outputFileName)); render(xml, out, xsl); return null; } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(xml); IOUtils.closeQuietly(in); IOUtils.closeQuietly(xsl); IOUtils.closeQuietly(xslt); } } }); } catch (final Exception e) { if (e instanceof ReportRenderException) throw (ReportRenderException) e; throw new ReportRenderException(e); } }
From source file:org.springframework.batch.core.partition.support.FlatFilePartitioner.java
/** * Returns the number of elements in the specified {@link Resource}. * * @param resource the resource// w w w. j a va 2 s. c om * @return the number of items contained in the resource */ protected LinesCount countItems(Resource resource) { try { final InputStream in = resource.getInputStream(); try { return countLinesAfterSkip(in); } finally { in.close(); } } catch (IOException e) { throw new IllegalStateException( "Unexpected IO exception while counting items for [" + resource.getDescription() + "]", e); } }
From source file:org.springframework.boot.config.PropertiesPropertySourceLoader.java
@Override public PropertySource<?> load(Resource resource) { try {//from ww w. j a v a2 s . c o m Properties properties = loadProperties(resource); // N.B. this is off by default unless user has supplied logback config in // standard location if (logger.isDebugEnabled()) { logger.debug("Properties loaded from " + resource + ": " + properties); } return new PropertiesPropertySource(resource.getDescription(), properties); } catch (IOException ex) { throw new IllegalStateException("Could not load properties from " + resource, ex); } }
From source file:org.springframework.boot.env.PropertySourcesLoader.java
/** * Load the profile-specific properties from the specified resource (if any) and add * it as the first source.// www . j a v a 2 s. co m * @param resource the source resource (may be {@code null}). * @param profile a specific profile to load or {@code null} to load the default. * @return the loaded property source or {@code null} * @throws IOException if the source cannot be loaded */ public PropertySource<?> load(Resource resource, String profile) throws IOException { return load(resource, resource.getDescription(), profile); }
From source file:org.springframework.cloud.stream.app.tensorflow.util.ModelExtractor.java
public byte[] getModel(Resource modelResource) { Assert.notNull(modelResource, "Not null model resource is required!"); try (InputStream is = modelResource.getInputStream(); InputStream bi = new BufferedInputStream(is)) { String[] archiveCompressor = detectArchiveAndCompressor(modelResource.getFilename()); String archive = archiveCompressor[0]; String compressor = archiveCompressor[1]; String fragment = modelResource.getURI().getFragment(); if (StringUtils.hasText(compressor)) { try (CompressorInputStream cis = new CompressorStreamFactory() .createCompressorInputStream(compressor, bi)) { if (StringUtils.hasText(archive)) { try (ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(archive, cis)) {//from w w w . j a va 2s .com // Compressor with Archive return findInArchiveStream(fragment, ais); } } else { // Compressor only return StreamUtils.copyToByteArray(cis); } } } else if (StringUtils.hasText(archive)) { // Archive only try (ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(archive, bi)) { return findInArchiveStream(fragment, ais); } } else { // No compressor nor Archive return StreamUtils.copyToByteArray(bi); } } catch (Exception e) { throw new IllegalStateException("Failed to extract a model from: " + modelResource.getDescription(), e); } }