com.lowagie.servlets
Class BufferedResponse

java.lang.Object
  extended byjavax.servlet.ServletResponseWrapper
      extended byjavax.servlet.http.HttpServletResponseWrapper
          extended bycom.lowagie.servlets.BufferedResponse
All Implemented Interfaces:
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

public class BufferedResponse
extends javax.servlet.http.HttpServletResponseWrapper

Wraps an HttpServletResponse instance, filtering any attempt to write or flush its output. The data written to the response is store in a memory buffer.

Author:
Marcelo Vanzin

Nested Class Summary
private static class BufferedResponse.ByteArrayServletStream
          Implements a ServletOutputStream that writes to a memory buffer.
 
Field Summary
private  String declaredContentType
           
private  int declaredLength
           
private  boolean isModified
           
private  BufferedResponse.ByteArrayServletStream out
           
private  PrintWriter wOut
           
 
Fields inherited from class javax.servlet.ServletResponseWrapper
 
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
BufferedResponse(javax.servlet.http.HttpServletResponse response)
          Constructs a new BufferedResponse, wrapping the response passed.
 
Method Summary
 void flushBuffer()
          Filters calls to flushBuffer() so that no data is written to the response before executing the output filter.
 InputStream getData()
          Returns a InputStream with the data currently stored in the memory buffer..
 String getDeclaredContentType()
          Returns the content type declared by the called resource.
 int getDeclaredLength()
          Returns the content length declared by the called resource.
 javax.servlet.ServletOutputStream getOutputStream()
          Returns a OutputStream to the memory buffer.
 PrintWriter getWriter()
          Returns a PrintWriter to the memory buffer.
 boolean isModified()
          Says if the resource called has been modified or not.
 void setContentLength(int length)
          Does not let the content length be set, but stores it in a variable in case it is needed later.
 void setContentType(String type)
          Does not let the content type be set, but stores it in a variable in case it is needed later.
 void setStatus(int sc)
          If the status set if SC_NOT_MODIFIED, sets a flag so that the output filter knows that the buffer may be empty.
 
Methods inherited from class javax.servlet.http.HttpServletResponseWrapper
addCookie, addDateHeader, addHeader, addIntHeader, containsHeader, encodeRedirectUrl, encodeRedirectURL, encodeUrl, encodeURL, sendError, sendError, sendRedirect, setDateHeader, setHeader, setIntHeader, setStatus
 
Methods inherited from class javax.servlet.ServletResponseWrapper
getBufferSize, getCharacterEncoding, getLocale, getResponse, isCommitted, reset, resetBuffer, setBufferSize, setLocale, setResponse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletResponse
getBufferSize, getCharacterEncoding, getLocale, isCommitted, reset, resetBuffer, setBufferSize, setLocale
 

Field Detail

out

private BufferedResponse.ByteArrayServletStream out

wOut

private PrintWriter wOut

declaredLength

private int declaredLength

isModified

private boolean isModified

declaredContentType

private String declaredContentType
Constructor Detail

BufferedResponse

public BufferedResponse(javax.servlet.http.HttpServletResponse response)
                 throws IOException

Constructs a new BufferedResponse, wrapping the response passed.

Parameters:
response - The original response from the filter chain..
Method Detail

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
                                                  throws IOException

Returns a OutputStream to the memory buffer.

Throws:
IOException

getWriter

public PrintWriter getWriter()
                      throws IOException

Returns a PrintWriter to the memory buffer.

Throws:
IOException

getData

public InputStream getData()
                    throws IOException

Returns a InputStream with the data currently stored in the memory buffer..

Throws:
IOException

setContentLength

public void setContentLength(int length)

Does not let the content length be set, but stores it in a variable in case it is needed later.


getDeclaredLength

public int getDeclaredLength()

Returns the content length declared by the called resource.


setContentType

public void setContentType(String type)

Does not let the content type be set, but stores it in a variable in case it is needed later.


getDeclaredContentType

public String getDeclaredContentType()
Returns the content type declared by the called resource.


setStatus

public void setStatus(int sc)

If the status set if SC_NOT_MODIFIED, sets a flag so that the output filter knows that the buffer may be empty. This is to prevent errors when a static resource is wrapped by the filter and the containers returns an empty buffer if the resource has not been modified.


isModified

public boolean isModified()
Says if the resource called has been modified or not.


flushBuffer

public void flushBuffer()
                 throws IOException
Filters calls to flushBuffer() so that no data is written to the response before executing the output filter.

Throws:
IOException