org.blojsom.filter
Class SimpleCompressionFilter

java.lang.Object
  extended byorg.blojsom.filter.SimpleCompressionFilter
All Implemented Interfaces:
javax.servlet.Filter

public class SimpleCompressionFilter
extends java.lang.Object
implements javax.servlet.Filter

Filter that compresses output with gzip (assuming that browser supports gzip).

Taken from More Servlets and JavaServer Pages from Prentice Hall and Sun Microsystems Press, http://www.moreservlets.com/. © 2002 Marty Hall; may be freely used or adapted.

Since:
blojsom 2.24
Version:
$Id: SimpleCompressionFilter.java,v 1.3 2006/01/04 16:59:54 czarneckid Exp $
Author:
Marty Hall, David Czarnecki

Constructor Summary
SimpleCompressionFilter()
           
 
Method Summary
 void destroy()
          Called when filter taken out of service
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          If browser does not support gzip, invoke resource normally.
protected  javax.servlet.FilterConfig getFilterConfig()
          Retrieve the FilterConfig object
 void init(javax.servlet.FilterConfig config)
          Store the FilterConfig object in case subclasses want it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleCompressionFilter

public SimpleCompressionFilter()
Method Detail

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws javax.servlet.ServletException,
                     java.io.IOException
If browser does not support gzip, invoke resource normally. If browser does support gzip, set the Content-Encoding response header and invoke resource with a wrapped response that collects all the output. Extract the output and write it into a gzipped byte array. Finally, write that array to the client's output stream.

Specified by:
doFilter in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException
java.io.IOException

init

public void init(javax.servlet.FilterConfig config)
          throws javax.servlet.ServletException
Store the FilterConfig object in case subclasses want it.

Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException

getFilterConfig

protected javax.servlet.FilterConfig getFilterConfig()
Retrieve the FilterConfig object

Returns:
FilterConfig

destroy

public void destroy()
Called when filter taken out of service

Specified by:
destroy in interface javax.servlet.Filter