ServletResponseWrapper (Servlet 4.0 API Documentation - Apache Tomcat 9.0.120)
Description: declaration: package: javax.servlet, class: ServletResponseWrapper

# Class ServletResponseWrapper

java.lang.Object
javax.servlet.ServletResponseWrapper

All Implemented Interfaces:
  `ServletResponse`

Direct Known Subclasses:
  `HttpServletResponseWrapper`

public class ServletResponseWrapper extends Object implements ServletResponse
Provides a convenient implementation of the ServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped response object.

Since:
  Servlet 2.3
See Also:
  - `ServletResponse`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ServletResponseWrapper(ServletResponse response)`
  Creates a ServletResponse adaptor wrapping the given response object.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `flushBuffer()`
  The default behavior of this method is to call flushBuffer() on the wrapped response object.
  `int`
  `getBufferSize()`
  The default behavior of this method is to return getBufferSize() on the wrapped response object.
  `String`
  `getCharacterEncoding()`
  The default behavior of this method is to return getCharacterEncoding() on the wrapped response object.
  `String`
  `getContentType()`
  The default behavior of this method is to return getContentType() on the wrapped response object.
  `Locale`
  `getLocale()`
  The default behavior of this method is to return getLocale() on the wrapped response object.
  `ServletOutputStream`
  `getOutputStream()`
  The default behavior of this method is to return getOutputStream() on the wrapped response object.
  `ServletResponse`
  `getResponse()`
  Return the wrapped ServletResponse object.
  `PrintWriter`
  `getWriter()`
  The default behavior of this method is to return getWriter() on the wrapped response object.
  `boolean`
  `isCommitted()`
  The default behavior of this method is to return isCommitted() on the wrapped response object.
  `boolean`
  `isWrapperFor(Class<?> wrappedType)`
  TODO SERVLET3 - Add comments
  `boolean`
  `isWrapperFor(ServletResponse wrapped)`
  TODO SERVLET3 - Add comments
  `void`
  `reset()`
  The default behavior of this method is to call reset() on the wrapped response object.
  `void`
  `resetBuffer()`
  The default behavior of this method is to call resetBuffer() on the wrapped response object.
  `void`
  `setBufferSize(int size)`
  The default behavior of this method is to call setBufferSize(int size) on the wrapped response object.
  `void`
  `setCharacterEncoding(String charset)`
  The default behavior of this method is to call setCharacterEncoding(String charset) on the wrapped response object.
  `void`
  `setContentLength(int len)`
  The default behavior of this method is to call setContentLength(int len) on the wrapped response object.
  `void`
  `setContentLengthLong(long length)`
  The default behavior of this method is to call setContentLengthLong(long len) on the wrapped response object.
  `void`
  `setContentType(String type)`
  The default behavior of this method is to call setContentType(String type) on the wrapped response object.
  `void`
  `setLocale(Locale loc)`
  The default behavior of this method is to call setLocale(Locale loc) on the wrapped response object.
  `void`
  `setResponse(ServletResponse response)`
  Sets the response being wrapped.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ServletResponseWrapper

    public ServletResponseWrapper(ServletResponse response)
    Creates a ServletResponse adaptor wrapping the given response object.
    Parameters:
      `response` - The response to wrap
    Throws:
      `IllegalArgumentException` - if the response is null.

- ## Method Details

  - ### getResponse

    public ServletResponse getResponse()
    Return the wrapped ServletResponse object.
    Returns:
      The wrapped ServletResponse object.

  - ### setResponse

    public void setResponse(ServletResponse response)
    Sets the response being wrapped.
    Parameters:
      `response` - The new response to wrap
    Throws:
      `IllegalArgumentException` - if the response is null.

  - ### setCharacterEncoding

    public void setCharacterEncoding(String charset)
    The default behavior of this method is to call setCharacterEncoding(String charset) on the wrapped response object.
    Specified by:
      `setCharacterEncoding` in interface `ServletResponse`
    Parameters:
      `charset` - a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets)
    Since:
      Servlet 2.4
    See Also:
      - #setLocale

  - ### getCharacterEncoding

    public String getCharacterEncoding()
    The default behavior of this method is to return getCharacterEncoding() on the wrapped response object.
    Specified by:
      `getCharacterEncoding` in interface `ServletResponse`
    Returns:
      a `String` specifying the name of the character encoding, for example, `UTF-8`

  - ### getOutputStream

    public ServletOutputStream getOutputStream() throws IOException
    The default behavior of this method is to return getOutputStream() on the wrapped response object.
    Specified by:
      `getOutputStream` in interface `ServletResponse`
    Returns:
      a `ServletOutputStream` for writing binary data
    Throws:
      `IOException` - if an input or output exception occurred
    See Also:
      - `ServletResponse.getWriter()`

  - ### getWriter

    public PrintWriter getWriter() throws IOException
    The default behavior of this method is to return getWriter() on the wrapped response object.
    Specified by:
      `getWriter` in interface `ServletResponse`
    Returns:
      a `PrintWriter` object that can return character data to the client
    Throws:
      `IOException` - if an input or output exception occurred
    See Also:
      - `ServletResponse.getOutputStream()`
      - `ServletResponse.setCharacterEncoding(String)`

  - ### setContentLength

    public void setContentLength(int len)
    The default behavior of this method is to call setContentLength(int len) on the wrapped response object.
    Specified by:
      `setContentLength` in interface `ServletResponse`
    Parameters:
      `len` - an integer specifying the length of the content being returned to the client; sets the Content-Length header

  - ### setContentLengthLong

    public void setContentLengthLong(long length)
    The default behavior of this method is to call setContentLengthLong(long len) on the wrapped response object.
    Specified by:
      `setContentLengthLong` in interface `ServletResponse`
    Parameters:
      `length` - an integer specifying the length of the content being returned to the client; sets the Content-Length header
    Since:
      Servlet 3.1

  - ### setContentType

    public void setContentType(String type)
    The default behavior of this method is to call setContentType(String type) on the wrapped response object.
    Specified by:
      `setContentType` in interface `ServletResponse`
    Parameters:
      `type` - a `String` specifying the MIME type of the content
    See Also:
      - `ServletResponse.setLocale(Locale)`
      - `ServletResponse.setCharacterEncoding(String)`
      - `ServletResponse.getOutputStream()`
      - `ServletResponse.getWriter()`

  - ### getContentType

    public String getContentType()
    The default behavior of this method is to return getContentType() on the wrapped response object.
    Specified by:
      `getContentType` in interface `ServletResponse`
    Returns:
      a `String` specifying the content type, for example, `text/html; charset=UTF-8`, or null
    Since:
      Servlet 2.4

  - ### setBufferSize

    public void setBufferSize(int size)
    The default behavior of this method is to call setBufferSize(int size) on the wrapped response object.
    Specified by:
      `setBufferSize` in interface `ServletResponse`
    Parameters:
      `size` - the preferred buffer size
    See Also:
      - `ServletResponse.getBufferSize()`
      - `ServletResponse.flushBuffer()`
      - `ServletResponse.isCommitted()`
      - `ServletResponse.reset()`

  - ### getBufferSize

    public int getBufferSize()
    The default behavior of this method is to return getBufferSize() on the wrapped response object.
    Specified by:
      `getBufferSize` in interface `ServletResponse`
    Returns:
      the actual buffer size used
    See Also:
      - `ServletResponse.setBufferSize(int)`
      - `ServletResponse.flushBuffer()`
      - `ServletResponse.isCommitted()`
      - `ServletResponse.reset()`

  - ### flushBuffer

    public void flushBuffer() throws IOException
    The default behavior of this method is to call flushBuffer() on the wrapped response object.
    Specified by:
      `flushBuffer` in interface `ServletResponse`
    Throws:
      `IOException` - if an I/O occurs during the flushing of the response
    See Also:
      - `ServletResponse.setBufferSize(int)`
      - `ServletResponse.getBufferSize()`
      - `ServletResponse.isCommitted()`
      - `ServletResponse.reset()`

  - ### isCommitted

    public boolean isCommitted()
    The default behavior of this method is to return isCommitted() on the wrapped response object.
    Specified by:
      `isCommitted` in interface `ServletResponse`
    Returns:
      a boolean indicating if the response has been committed
    See Also:
      - `ServletResponse.setBufferSize(int)`
      - `ServletResponse.getBufferSize()`
      - `ServletResponse.flushBuffer()`
      - `ServletResponse.reset()`

  - ### reset

    public void reset()
    The default behavior of this method is to call reset() on the wrapped response object.
    Specified by:
      `reset` in interface `ServletResponse`
    See Also:
      - `ServletResponse.setBufferSize(int)`
      - `ServletResponse.getBufferSize()`
      - `ServletResponse.flushBuffer()`
      - `ServletResponse.isCommitted()`

  - ### resetBuffer

    public void resetBuffer()
    The default behavior of this method is to call resetBuffer() on the wrapped response object.
    Specified by:
      `resetBuffer` in interface `ServletResponse`
    See Also:
      - `ServletResponse.setBufferSize(int)`
      - `ServletResponse.getBufferSize()`
      - `ServletResponse.isCommitted()`
      - `ServletResponse.reset()`

  - ### setLocale

    public void setLocale(Locale loc)
    The default behavior of this method is to call setLocale(Locale loc) on the wrapped response object.
    Specified by:
      `setLocale` in interface `ServletResponse`
    Parameters:
      `loc` - the locale of the response
    See Also:
      - `ServletResponse.getLocale()`
      - `ServletResponse.setContentType(String)`
      - `ServletResponse.setCharacterEncoding(String)`

  - ### getLocale

    public Locale getLocale()
    The default behavior of this method is to return getLocale() on the wrapped response object.
    Specified by:
      `getLocale` in interface `ServletResponse`
    Returns:
      The locale specified for this response using the `ServletResponse.setLocale(Locale)` method. If no locale has been specified, the container's default locale is returned.
    See Also:
      - `ServletResponse.setLocale(Locale)`

  - ### isWrapperFor

    public boolean isWrapperFor(ServletResponse wrapped)
    TODO SERVLET3 - Add comments
    Parameters:
      `wrapped` - The response to compare to the wrapped response
    Returns:
      `true` if the response wrapped by this wrapper (or series of wrappers) is the same as the supplied response, otherwise `false`
    Since:
      Servlet 3.0

  - ### isWrapperFor

    public boolean isWrapperFor(Class<?> wrappedType)
    TODO SERVLET3 - Add comments
    Parameters:
      `wrappedType` - The class to compare to the class of the wrapped response
    Returns:
      `true` if the response wrapped by this wrapper (or series of wrappers) is the same type as the supplied type, otherwise `false`
    Since:
      Servlet 3.0