## org.mortbay.servlet
Class GzipFilter

    java.lang.Object
      org.mortbay.servlet.UserAgentFilter
          org.mortbay.servlet.GzipFilter

All Implemented Interfaces:
  javax.servlet.Filter

Direct Known Subclasses:
  IncludableGzipFilter

    public class GzipFilter

extends UserAgentFilter

GZIP Filter This filter will gzip the content of a response iff:

- The filter is mapped to a matching path
- The response status code is >=200 and <300
- The content length is unknown or more than the `minGzipSize` initParameter or the minGzipSize is 0(default)
- The content-type is in the comma separated list of mimeTypes set in the `mimeTypes` initParameter or if no mimeTypes are defined the content-type is not "application/gzip"
- No content-encoding is specified by the resource

Compressing the content can greatly improve the network bandwidth usage, but at a cost of memory and CPU cycles. If this filter is mapped for static content, then use of efficient direct NIO may be prevented, thus use of the gzip mechanism of the `DefaultServlet` is advised instead.

This filter extends `UserAgentFilter` and if the the initParameter `excludedAgents` is set to a comma separated list of user agents, then these agents will be excluded from gzip content.

Author:
  gregw

Nested Class Summary
`class` `GzipFilter.GZIPResponseWrapper`
`static class` `GzipFilter.GzipStream`

Field Summary
`protected int` `_bufferSize`
`protected java.util.Set` `_excluded`
`protected java.util.Set` `_mimeTypes`
`protected int` `_minGzipSize`

Constructor Summary
`GzipFilter()`

Method Summary
`void` `destroy()`
`void` `doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)`
`void` `init(javax.servlet.FilterConfig filterConfig)`
`protected GzipFilter.GZIPResponseWrapper` `newGZIPResponseWrapper(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)`
`protected java.io.PrintWriter` `newWriter(java.io.OutputStream out, java.lang.String encoding)`

Methods inherited from class org.mortbay.servlet.UserAgentFilter
`getUserAgent, getUserAgent`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### _mimeTypes

    protected java.util.Set _mimeTypes

### _bufferSize

    protected int _bufferSize

### _minGzipSize

    protected int _minGzipSize

### _excluded

    protected java.util.Set _excluded

Constructor Detail

### GzipFilter

    public GzipFilter()

Method Detail

### init

    public void init(javax.servlet.FilterConfig filterConfig)
              throws javax.servlet.ServletException

  Specified by:
    `init` in interface `javax.servlet.Filter`
  Overrides:
    `init` in class `UserAgentFilter`
  Throws:
    `javax.servlet.ServletException`

### destroy

    public void destroy()

  Specified by:
    `destroy` in interface `javax.servlet.Filter`
  Overrides:
    `destroy` in class `UserAgentFilter`

### doFilter

    public void doFilter(javax.servlet.ServletRequest req,
                         javax.servlet.ServletResponse res,
                         javax.servlet.FilterChain chain)
                  throws java.io.IOException,
                         javax.servlet.ServletException

  Specified by:
    `doFilter` in interface `javax.servlet.Filter`
  Overrides:
    `doFilter` in class `UserAgentFilter`
  Throws:
    `java.io.IOException`
    `javax.servlet.ServletException`

### newGZIPResponseWrapper

    protected GzipFilter.GZIPResponseWrapper newGZIPResponseWrapper(javax.servlet.http.HttpServletRequest request,
                                                                    javax.servlet.http.HttpServletResponse response)

### newWriter

    protected java.io.PrintWriter newWriter(java.io.OutputStream out,
                                            java.lang.String encoding)
                                     throws java.io.UnsupportedEncodingException

  Throws:
    `java.io.UnsupportedEncodingException`

Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.