Package jakarta.servlet
Class ServletResponseWrapper
java.lang.Object
jakarta.servlet.ServletResponseWrapper
- All Implemented Interfaces:
- ServletResponse
- Direct Known Subclasses:
- HttpServletResponseWrapper
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:
- 
Constructor SummaryConstructorsConstructorDescriptionServletResponseWrapper(ServletResponse response) Creates a ServletResponse adaptor wrapping the given response object.
- 
Method SummaryModifier and TypeMethodDescriptionvoidThe default behavior of this method is to call flushBuffer() on the wrapped response object.intThe default behavior of this method is to return getBufferSize() on the wrapped response object.The default behavior of this method is to return getCharacterEncoding() on the wrapped response object.The default behavior of this method is to return getContentType() on the wrapped response object.The default behavior of this method is to return getLocale() on the wrapped response object.The default behavior of this method is to return getOutputStream() on the wrapped response object.Return the wrapped ServletResponse object.The default behavior of this method is to return getWriter() on the wrapped response object.booleanThe default behavior of this method is to return isCommitted() on the wrapped response object.booleanisWrapperFor(ServletResponse wrapped) TODO SERVLET3 - Add commentsbooleanisWrapperFor(Class<?> wrappedType) TODO SERVLET3 - Add commentsvoidreset()The default behavior of this method is to call reset() on the wrapped response object.voidThe default behavior of this method is to call resetBuffer() on the wrapped response object.voidsetBufferSize(int size) The default behavior of this method is to call setBufferSize(int size) on the wrapped response object.voidsetCharacterEncoding(String charset) The default behavior of this method is to call setCharacterEncoding(String charset) on the wrapped response object.voidsetContentLength(int len) The default behavior of this method is to call setContentLength(int len) on the wrapped response object.voidsetContentLengthLong(long length) The default behavior of this method is to call setContentLengthLong(long len) on the wrapped response object.voidsetContentType(String type) The default behavior of this method is to call setContentType(String type) on the wrapped response object.voidThe default behavior of this method is to call setLocale(Locale loc) on the wrapped response object.voidsetResponse(ServletResponse response) Sets the response being wrapped.
- 
Constructor Details- 
ServletResponseWrapperCreates a ServletResponse adaptor wrapping the given response object.- Parameters:
- response- The response to wrap
- Throws:
- IllegalArgumentException- if the response is null.
 
 
- 
- 
Method Details- 
getResponseReturn the wrapped ServletResponse object.- Returns:
- The wrapped ServletResponse object.
 
- 
setResponseSets the response being wrapped.- Parameters:
- response- The new response to wrap
- Throws:
- IllegalArgumentException- if the response is null.
 
- 
setCharacterEncodingThe default behavior of this method is to call setCharacterEncoding(String charset) on the wrapped response object.- Specified by:
- setCharacterEncodingin 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:
 
- 
getCharacterEncodingThe default behavior of this method is to return getCharacterEncoding() on the wrapped response object.- Specified by:
- getCharacterEncodingin interface- ServletResponse
- Returns:
- a Stringspecifying the name of the character encoding, for example,UTF-8
 
- 
getOutputStreamThe default behavior of this method is to return getOutputStream() on the wrapped response object.- Specified by:
- getOutputStreamin interface- ServletResponse
- Returns:
- a ServletOutputStreamfor writing binary data
- Throws:
- IOException- if an input or output exception occurred
- See Also:
 
- 
getWriterThe default behavior of this method is to return getWriter() on the wrapped response object.- Specified by:
- getWriterin interface- ServletResponse
- Returns:
- a PrintWriterobject that can return character data to the client
- Throws:
- UnsupportedEncodingException- if the character encoding returned by- getCharacterEncodingcannot be used
- IOException- if an input or output exception occurred
- See Also:
 
- 
setContentLengthpublic void setContentLength(int len) The default behavior of this method is to call setContentLength(int len) on the wrapped response object.- Specified by:
- setContentLengthin interface- ServletResponse
- Parameters:
- len- an integer specifying the length of the content being returned to the client; sets the Content-Length header
 
- 
setContentLengthLongpublic void setContentLengthLong(long length) The default behavior of this method is to call setContentLengthLong(long len) on the wrapped response object.- Specified by:
- setContentLengthLongin 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
 
- 
setContentTypeThe default behavior of this method is to call setContentType(String type) on the wrapped response object.- Specified by:
- setContentTypein interface- ServletResponse
- Parameters:
- type- a- Stringspecifying the MIME type of the content
- See Also:
 
- 
getContentTypeThe default behavior of this method is to return getContentType() on the wrapped response object.- Specified by:
- getContentTypein interface- ServletResponse
- Returns:
- a Stringspecifying the content type, for example,text/html; charset=UTF-8, or null
- Since:
- Servlet 2.4
 
- 
setBufferSizepublic void setBufferSize(int size) The default behavior of this method is to call setBufferSize(int size) on the wrapped response object.- Specified by:
- setBufferSizein interface- ServletResponse
- Parameters:
- size- the preferred buffer size
- See Also:
 
- 
getBufferSizepublic int getBufferSize()The default behavior of this method is to return getBufferSize() on the wrapped response object.- Specified by:
- getBufferSizein interface- ServletResponse
- Returns:
- the actual buffer size used
- See Also:
 
- 
flushBufferThe default behavior of this method is to call flushBuffer() on the wrapped response object.- Specified by:
- flushBufferin interface- ServletResponse
- Throws:
- IOException- if an I/O occurs during the flushing of the response
- See Also:
 
- 
isCommittedpublic boolean isCommitted()The default behavior of this method is to return isCommitted() on the wrapped response object.- Specified by:
- isCommittedin interface- ServletResponse
- Returns:
- a boolean indicating if the response has been committed
- See Also:
 
- 
resetpublic void reset()The default behavior of this method is to call reset() on the wrapped response object.- Specified by:
- resetin interface- ServletResponse
- See Also:
 
- 
resetBufferpublic void resetBuffer()The default behavior of this method is to call resetBuffer() on the wrapped response object.- Specified by:
- resetBufferin interface- ServletResponse
- See Also:
 
- 
setLocaleThe default behavior of this method is to call setLocale(Locale loc) on the wrapped response object.- Specified by:
- setLocalein interface- ServletResponse
- Parameters:
- loc- the locale of the response
- See Also:
 
- 
getLocaleThe default behavior of this method is to return getLocale() on the wrapped response object.- Specified by:
- getLocalein interface- ServletResponse
- Returns:
- The locale specified for this response using the ServletResponse.setLocale(java.util.Locale)method. If no locale has been specified, the container's default locale is returned.
- See Also:
 
- 
isWrapperForTODO SERVLET3 - Add comments- Parameters:
- wrapped- The response to compare to the wrapped response
- Returns:
- trueif the response wrapped by this wrapper (or series of wrappers) is the same as the supplied response, otherwise- false
- Since:
- Servlet 3.0
 
- 
isWrapperForTODO SERVLET3 - Add comments- Parameters:
- wrappedType- The class to compare to the class of the wrapped response
- Returns:
- trueif the response wrapped by this wrapper (or series of wrappers) is the same type as the supplied type, otherwise- false
- Since:
- Servlet 3.0
 
 
-