javax.servlet
Class ServletResponseWrapper

java.lang.Object
  extended by javax.servlet.ServletResponseWrapper
All Implemented Interfaces:
ServletResponse
Direct Known Subclasses:
HttpServletResponseWrapper

public class ServletResponseWrapper
extends java.lang.Object
implements ServletResponse

Wraps a servlet response in another response. Filters may use ServletResponseWrapper to grab results from the servlet.

The default methods just call the wrapped response methods.

Since:
servlet 2.3

Constructor Summary
ServletResponseWrapper(ServletResponse response)
          Create a new ServletResponseWrapper, wrapping a specified response.
 
Method Summary
 void flushBuffer()
          Flushes the buffer to the client.
 int getBufferSize()
          Returns the size of the output buffer.
 java.lang.String getCharacterEncoding()
          Returns the character encoding the response is using for output.
 java.lang.String getContentType()
          Returns the content type
 java.util.Locale getLocale()
          Returns the output locale.
 ServletOutputStream getOutputStream()
          Returns an output stream for writing to the client.
 ServletResponse getResponse()
          Gets the wrapped response
 java.io.PrintWriter getWriter()
          Returns a PrintWriter with the proper character encoding for writing text data to the client.
 boolean isCommitted()
          Returns true if some data has actually been send to the client.
 boolean isWrapperFor(java.lang.Class wrappedType)
           
 boolean isWrapperFor(ServletResponse wrapped)
           
 void reset()
          Resets the output stream, clearing headers and the output buffer.
 void resetBuffer()
          Resets the output stream without clearing headers and the output buffer.
 void setBufferSize(int size)
          Sets the output buffer size to size.
 void setCharacterEncoding(java.lang.String encoding)
          Sets the character encoding the response is using for output.
 void setContentLength(int len)
          Deprecated.  
 void setContentType(java.lang.String type)
          Sets the response content type.
 void setLocale(java.util.Locale locale)
          Sets the output locale.
 void setResponse(ServletResponse response)
          Sets the response to be wrapped.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletResponseWrapper

public ServletResponseWrapper(ServletResponse response)
Create a new ServletResponseWrapper, wrapping a specified response.

Parameters:
response - the response to wrap.
Method Detail

setResponse

public void setResponse(ServletResponse response)
Sets the response to be wrapped.

Parameters:
response - the response to wrap.

getResponse

public ServletResponse getResponse()
Gets the wrapped response

Returns:
the wrapped response

setContentType

public void setContentType(java.lang.String type)
Sets the response content type. The content type includes the character encoding. The content type must be set before calling getWriter() so the writer can use the proper character encoding.

To set the output character encoding to ISO-8859-2, use the following:

 response.setContentType("text/html; charset=ISO-8859-2");
 

Specified by:
setContentType in interface ServletResponse
Parameters:
type - the mime type of the output

getContentType

public java.lang.String getContentType()
Returns the content type

Specified by:
getContentType in interface ServletResponse
Since:
2.4

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Returns the character encoding the response is using for output.

Specified by:
getCharacterEncoding in interface ServletResponse

setCharacterEncoding

public void setCharacterEncoding(java.lang.String encoding)
Sets the character encoding the response is using for output.

Specified by:
setCharacterEncoding in interface ServletResponse
Since:
2.4

setLocale

public void setLocale(java.util.Locale locale)
Sets the output locale. The response will set the character encoding based on the locale. For example, setting the "kr" locale will set the character encoding to "EUC_KR".

Specified by:
setLocale in interface ServletResponse

getLocale

public java.util.Locale getLocale()
Returns the output locale.

Specified by:
getLocale in interface ServletResponse

getOutputStream

public ServletOutputStream getOutputStream()
                                    throws java.io.IOException
Returns an output stream for writing to the client. You can use the output stream to write binary data.

Specified by:
getOutputStream in interface ServletResponse
Throws:
java.io.IOException

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
Returns a PrintWriter with the proper character encoding for writing text data to the client.

Specified by:
getWriter in interface ServletResponse
Throws:
java.io.IOException

setBufferSize

public void setBufferSize(int size)
Sets the output buffer size to size. The servlet engine may round the size up.

Specified by:
setBufferSize in interface ServletResponse
Parameters:
size - the new output buffer size.

getBufferSize

public int getBufferSize()
Returns the size of the output buffer.

Specified by:
getBufferSize in interface ServletResponse

flushBuffer

public void flushBuffer()
                 throws java.io.IOException
Flushes the buffer to the client.

Specified by:
flushBuffer in interface ServletResponse
Throws:
java.io.IOException

isCommitted

public boolean isCommitted()
Returns true if some data has actually been send to the client. The data will be sent if the buffer overflows or if it's explicitly flushed.

Specified by:
isCommitted in interface ServletResponse

reset

public void reset()
Resets the output stream, clearing headers and the output buffer. Calling reset() after data has been committed is illegal.

Specified by:
reset in interface ServletResponse
Throws:
java.lang.IllegalStateException - if isCommitted() is true.

resetBuffer

public void resetBuffer()
Resets the output stream without clearing headers and the output buffer. Calling resetBuffer() after data has been committed is illegal.

Specified by:
resetBuffer in interface ServletResponse
Throws:
java.lang.IllegalStateException - if isCommitted() is true.

setContentLength

public void setContentLength(int len)
Deprecated. 

Resin automatically handles output content length and chunking. This method is ignored.

Specified by:
setContentLength in interface ServletResponse

isWrapperFor

public boolean isWrapperFor(ServletResponse wrapped)
Since:
Servlet 3.0

isWrapperFor

public boolean isWrapperFor(java.lang.Class wrappedType)
Since:
Servlet 3.0