Search in sources :

Example 1 with FastByteArrayOutputStream

use of org.springframework.util.FastByteArrayOutputStream in project BroadleafCommerce by BroadleafCommerce.

the class CachingCompressedResponseFilter method processDynamic.

protected void processDynamic(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
    ContentCachingResponseWrapper wrapper = new ContentCachingResponseWrapper(response);
    chain.doFilter(request, wrapper);
    FastByteArrayOutputStream baos = new FastByteArrayOutputStream(1024);
    GZIPOutputStream zip = new GZIPOutputStream(baos);
    StreamUtils.copy(wrapper.getContentInputStream(), zip);
    zip.close();
    response.addHeader("Content-Encoding", "gzip");
    response.setContentLength(baos.size());
    StreamUtils.copy(new ByteArrayInputStream(baos.toByteArray()), response.getOutputStream());
}
Also used : ContentCachingResponseWrapper(org.springframework.web.util.ContentCachingResponseWrapper) FastByteArrayOutputStream(org.springframework.util.FastByteArrayOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 FastByteArrayOutputStream (org.springframework.util.FastByteArrayOutputStream)1 ContentCachingResponseWrapper (org.springframework.web.util.ContentCachingResponseWrapper)1