java.lang.Object
org.roller.presentation.filters.CompressionFilter
- All Implemented Interfaces:
- javax.servlet.Filter
- public class CompressionFilter
- 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.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
mLogger
private static org.apache.commons.logging.Log mLogger
config
private javax.servlet.FilterConfig config
CompressionFilter
public CompressionFilter()
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
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
getFilterConfig
protected javax.servlet.FilterConfig getFilterConfig()
destroy
public void destroy()
- Description copied from interface:
javax.servlet.Filter
- Called by the web container to indicate to a filter that it is being taken out of service. This
method is only called once all threads within the filter's doFilter method have exited or after
a timeout period has passed. After the web container calls this method, it will not call the
doFilter method again on this instance of the filter.
This method gives the filter an opportunity to clean up any resources that are being held (for
example, memory, file handles, threads) and make sure that any persistent state is synchronized
with the filter's current state in memory.
- Specified by:
destroy in interface javax.servlet.Filter
isGzipSupported
private boolean isGzipSupported(javax.servlet.http.HttpServletRequest req)