EchoPoint
1.0

echopoint.servlet
Class CompressingHttpServletResponse

java.lang.Object
  extended byechopoint.servlet.CompressingHttpServletResponse
All Implemented Interfaces:
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

public class CompressingHttpServletResponse
extends java.lang.Object
implements javax.servlet.http.HttpServletResponse

CompressingHttpServletResponse is HttpServletResponse that can compress data back to the client browser if it indicates that it can accept encoded data. It will only encode text data (eg "Content-Type" "text/html" or "text/javascript")

Other data, such as image data, is typically compressed and does not need more compression. In fact testing has shown that compression image data can increase it size and interfere with the client browsers ability to render it.

The standard java.util.zip.GZIPOutputStream compression code is used and the "Content-Encoding" will be set to "gzip".

Author:
Brad Baker

Field Summary
 
Fields inherited from interface javax.servlet.http.HttpServletResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
 
Constructor Summary
protected CompressingHttpServletResponse(javax.servlet.http.HttpServletResponse response, boolean areBytesAccumulated)
          Constructs a CompressingHttpServletResponse that compresses the data that is returned by a HttpServletResponse.
 
Method Summary
 void addCookie(javax.servlet.http.Cookie arg0)
           
 void addDateHeader(java.lang.String arg0, long arg1)
           
 void addHeader(java.lang.String arg0, java.lang.String arg1)
           
 void addIntHeader(java.lang.String arg0, int arg1)
           
 boolean containsHeader(java.lang.String arg0)
           
 java.lang.String encodeRedirectUrl(java.lang.String arg0)
          Deprecated.  
 java.lang.String encodeRedirectURL(java.lang.String arg0)
           
 java.lang.String encodeUrl(java.lang.String arg0)
          Deprecated.  
 java.lang.String encodeURL(java.lang.String arg0)
           
 boolean equals(java.lang.Object obj)
           
 void flushBuffer()
           
 int getBufferSize()
           
 java.lang.String getCharacterEncoding()
           
static javax.servlet.http.HttpServletResponse getInstance(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          This methods returns a HttpServletResponse that may compress the data that is sent back to the browser.
 java.util.Locale getLocale()
           
 javax.servlet.ServletOutputStream getOutputStream()
           
 java.io.PrintWriter getWriter()
           
 int hashCode()
           
 boolean isCommitted()
           
 void reset()
           
 void resetBuffer()
           
 void sendError(int arg0)
           
 void sendError(int arg0, java.lang.String arg1)
           
 void sendRedirect(java.lang.String arg0)
           
 void setBufferSize(int arg0)
           
 void setContentLength(int contentLength)
           
 void setContentType(java.lang.String contentType)
           
 void setDateHeader(java.lang.String arg0, long arg1)
           
 void setHeader(java.lang.String arg0, java.lang.String arg1)
           
 void setIntHeader(java.lang.String arg0, int arg1)
           
 void setLocale(java.util.Locale arg0)
           
 void setStatus(int arg0)
           
 void setStatus(int arg0, java.lang.String arg1)
          Deprecated.  
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompressingHttpServletResponse

protected CompressingHttpServletResponse(javax.servlet.http.HttpServletResponse response,
                                         boolean areBytesAccumulated)
Constructs a CompressingHttpServletResponse that compresses the data that is returned by a HttpServletResponse.

Parameters:
response - - the HttpServletResponse to compress data for
areBytesAccumulated - - indicates whether bytes should be accumulated in memory first so that the "Content-Length" header can be accurately set. This is generally not needed in most browsers.
Method Detail

getInstance

public static javax.servlet.http.HttpServletResponse getInstance(javax.servlet.http.HttpServletRequest request,
                                                                 javax.servlet.http.HttpServletResponse response)
This methods returns a HttpServletResponse that may compress the data that is sent back to the browser. A check is done to ensure that the browser accepts compressed encoding. If it doesn't then response is passed back unchanged.

Parameters:
request - - the original HttpServletRequest
response - - the original HttpServletResponse
Returns:
a compressing HttpServletResponse or the original one if the browser does not accept compression.

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
                                                  throws java.io.IOException
Specified by:
getOutputStream in interface javax.servlet.ServletResponse
Throws:
java.io.IOException
See Also:
ServletResponse.getOutputStream()

setContentLength

public void setContentLength(int contentLength)
Specified by:
setContentLength in interface javax.servlet.ServletResponse
See Also:
ServletResponse.setContentLength(int)

setContentType

public void setContentType(java.lang.String contentType)
Specified by:
setContentType in interface javax.servlet.ServletResponse
See Also:
ServletResponse.setContentType(java.lang.String)

setBufferSize

public void setBufferSize(int arg0)
Specified by:
setBufferSize in interface javax.servlet.ServletResponse
See Also:
ServletResponse.setBufferSize(int)

flushBuffer

public void flushBuffer()
                 throws java.io.IOException
Specified by:
flushBuffer in interface javax.servlet.ServletResponse
Throws:
java.io.IOException
See Also:
ServletResponse.flushBuffer()

getBufferSize

public int getBufferSize()
Specified by:
getBufferSize in interface javax.servlet.ServletResponse
See Also:
ServletResponse.getBufferSize()

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
Specified by:
getWriter in interface javax.servlet.ServletResponse
Throws:
java.io.IOException
See Also:
ServletResponse.getWriter()

addCookie

public void addCookie(javax.servlet.http.Cookie arg0)
Specified by:
addCookie in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.addCookie(javax.servlet.http.Cookie)

addDateHeader

public void addDateHeader(java.lang.String arg0,
                          long arg1)
Specified by:
addDateHeader in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.addDateHeader(java.lang.String, long)

addHeader

public void addHeader(java.lang.String arg0,
                      java.lang.String arg1)
Specified by:
addHeader in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.addHeader(java.lang.String, java.lang.String)

addIntHeader

public void addIntHeader(java.lang.String arg0,
                         int arg1)
Specified by:
addIntHeader in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.addIntHeader(java.lang.String, int)

containsHeader

public boolean containsHeader(java.lang.String arg0)
Specified by:
containsHeader in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.containsHeader(java.lang.String)

encodeRedirectUrl

public java.lang.String encodeRedirectUrl(java.lang.String arg0)
Deprecated.  

Specified by:
encodeRedirectUrl in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.encodeRedirectUrl(java.lang.String)

encodeRedirectURL

public java.lang.String encodeRedirectURL(java.lang.String arg0)
Specified by:
encodeRedirectURL in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.encodeRedirectURL(java.lang.String)

encodeUrl

public java.lang.String encodeUrl(java.lang.String arg0)
Deprecated.  

Specified by:
encodeUrl in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.encodeUrl(java.lang.String)

encodeURL

public java.lang.String encodeURL(java.lang.String arg0)
Specified by:
encodeURL in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.encodeURL(java.lang.String)

equals

public boolean equals(java.lang.Object obj)
See Also:
Object.equals(java.lang.Object)

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Specified by:
getCharacterEncoding in interface javax.servlet.ServletResponse
See Also:
ServletResponse.getCharacterEncoding()

getLocale

public java.util.Locale getLocale()
Specified by:
getLocale in interface javax.servlet.ServletResponse
See Also:
ServletResponse.getLocale()

hashCode

public int hashCode()
See Also:
Object.hashCode()

isCommitted

public boolean isCommitted()
Specified by:
isCommitted in interface javax.servlet.ServletResponse
See Also:
ServletResponse.isCommitted()

reset

public void reset()
Specified by:
reset in interface javax.servlet.ServletResponse
See Also:
ServletResponse.reset()

resetBuffer

public void resetBuffer()
Specified by:
resetBuffer in interface javax.servlet.ServletResponse
See Also:
ServletResponse.resetBuffer()

sendError

public void sendError(int arg0)
               throws java.io.IOException
Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Throws:
java.io.IOException
See Also:
HttpServletResponse.sendError(int)

sendError

public void sendError(int arg0,
                      java.lang.String arg1)
               throws java.io.IOException
Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Throws:
java.io.IOException
See Also:
HttpServletResponse.sendError(int, java.lang.String)

sendRedirect

public void sendRedirect(java.lang.String arg0)
                  throws java.io.IOException
Specified by:
sendRedirect in interface javax.servlet.http.HttpServletResponse
Throws:
java.io.IOException
See Also:
HttpServletResponse.sendRedirect(java.lang.String)

setDateHeader

public void setDateHeader(java.lang.String arg0,
                          long arg1)
Specified by:
setDateHeader in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.setDateHeader(java.lang.String, long)

setHeader

public void setHeader(java.lang.String arg0,
                      java.lang.String arg1)
Specified by:
setHeader in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.setHeader(java.lang.String, java.lang.String)

setIntHeader

public void setIntHeader(java.lang.String arg0,
                         int arg1)
Specified by:
setIntHeader in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.setIntHeader(java.lang.String, int)

setLocale

public void setLocale(java.util.Locale arg0)
Specified by:
setLocale in interface javax.servlet.ServletResponse
See Also:
ServletResponse.setLocale(java.util.Locale)

setStatus

public void setStatus(int arg0)
Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.setStatus(int)

setStatus

public void setStatus(int arg0,
                      java.lang.String arg1)
Deprecated.  

Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
See Also:
HttpServletResponse.setStatus(int, java.lang.String)

toString

public java.lang.String toString()
See Also:
Object.toString()

EchoPoint
1.0