public String getContentType() { return originalResource.getContentType(); } }
public boolean isResourceModified(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { return originalResource.isResourceModified(httpServletRequest, httpServletResponse); }
@Override public SourceMap writeTo(OutputStream out, boolean isSourceMapEnabled) { try { downloadableResource.streamResource(out); } catch (DownloadException e) { Support.LOGGER.debug("Error while serving file: DownloadException"); } return sourceMap; } };
public void streamResource(OutputStream outputStream) throws DownloadException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); originalResource.streamResource(buffer); OutputStreamWriter out = new OutputStreamWriter(outputStream); try { out.write("speakeasyRequire.def('" + variableName + "', ['require', 'exports'], function(require, exports) {exports.render = function(data) {return require('speakeasy/mustache').to_html(\""); InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())); JavascriptEscaper.escape(reader, out); out.write("\", data);};});"); out.flush(); } catch (IOException e) { throw new DownloadException("Unable to read resource", e); } }
/** * Write apply a given transform a resource and then write the transformed content * to the supplied OutputStream. * Note that the OutputStream will not be closed by this method. * @param originalResource - the resource to transform * @param encoding - the encoding to use for writing * @param out - the output stream * @param transform - a function for transforming the content * @throws DownloadException - thrown if it is not possible to stream the output * @since 2.9.0 */ public static void transformAndStreamResource(final DownloadableResource originalResource, final Charset encoding, final OutputStream out, final Function<CharSequence, CharSequence> transform) throws DownloadException { try { final StringWriter writer = new StringWriter(); final WriterOutputStream output = new WriterOutputStream(writer, encoding); originalResource.streamResource(output); output.flush(); IOUtils.copy(new CharSequenceReader(transform.apply(writer.getBuffer().toString())), out, encoding.name()); } catch (final IOException e) { throw new DownloadException("Unable to stream to the output", e); } }}
public String getContentType() { return originalResource.getContentType(); }
public boolean isResourceModified(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { return originalResource.isResourceModified(httpServletRequest, httpServletResponse); }
/** * Adapter, turns DownloadableResource into Content. */ public static Content asContent(final DownloadableResource downloadableResource, final SourceMap sourceMap, boolean isTransformed) { return new ContentImpl(downloadableResource.getContentType(), isTransformed) { @Override public SourceMap writeTo(OutputStream out, boolean isSourceMapEnabled) { try { downloadableResource.streamResource(out); } catch (DownloadException e) { Support.LOGGER.debug("Error while serving file: DownloadException"); } return sourceMap; } }; }