Top Description Fields Constructors Methods
jakarta.servlet

public Class ServletResponseWrapper

extends Object
implements ServletResponse
Class Inheritance
All Implemented Interfaces
jakarta.servlet.ServletResponse
Known Direct Subclasses
jakarta.servlet.http.HttpServletResponseWrapper
Imports
java.io.IOException, .PrintWriter, java.nio.charset.Charset, java.util.Locale

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.
Author
Various
Since
Servlet 2.3
See Also
jakarta.servlet.ServletResponse

Field Summary

Modifier and TypeField and Description
private ServletResponse

Constructor Summary

AccessConstructor and Description
public
ServletResponseWrapper(ServletResponse
the ServletResponse to be wrapped
response
)

Creates a ServletResponse adaptor wrapping the given response object.

Method Summary

Modifier and TypeMethod and Description
public void
flushBuffer()

Implements jakarta.servlet.ServletResponse.flushBuffer.

The default behavior of this method is to call flushBuffer() on the wrapped response object.

public int
getBufferSize()

Implements jakarta.servlet.ServletResponse.getBufferSize.

The default behavior of this method is to return getBufferSize() on the wrapped response object.

public String
getCharacterEncoding()

Implements jakarta.servlet.ServletResponse.getCharacterEncoding.

The default behavior of this method is to return getCharacterEncoding() on the wrapped response object.

public String
getContentType()

Implements jakarta.servlet.ServletResponse.getContentType.

The default behavior of this method is to return getContentType() on the wrapped response object.

public Locale
getLocale()

Implements jakarta.servlet.ServletResponse.getLocale.

The default behavior of this method is to return getLocale() on the wrapped response object.

public ServletOutputStream
getOutputStream()

Implements jakarta.servlet.ServletResponse.getOutputStream.

The default behavior of this method is to return getOutputStream() on the wrapped response object.

public ServletResponse

Returns:

the wrapped ServletResponse
getResponse
()

Return the wrapped ServletResponse object.

public PrintWriter
getWriter()

Implements jakarta.servlet.ServletResponse.getWriter.

The default behavior of this method is to return getWriter() on the wrapped response object.

public boolean
isCommitted()

Implements jakarta.servlet.ServletResponse.isCommitted.

The default behavior of this method is to return isCommitted() on the wrapped response object.

public boolean

Returns:

true if this ServletResponseWrapper wraps the given ServletResponse instance, false otherwise
isWrapperFor
(ServletResponse
the ServletResponse instance to search for
wrapped
)

Checks (recursively) if this ServletResponseWrapper wraps the given ServletResponse instance.

public boolean

Returns:

true if this ServletResponseWrapper wraps a ServletResponse of the given class type, false otherwise
isWrapperFor
(Class<?>
the ServletResponse class type to search for
wrappedType
)

Checks (recursively) if this ServletResponseWrapper wraps a ServletResponse of the given class type.

public void
reset()

Implements jakarta.servlet.ServletResponse.reset.

The default behavior of this method is to call reset() on the wrapped response object.

public void
resetBuffer()

Implements jakarta.servlet.ServletResponse.resetBuffer.

The default behavior of this method is to call resetBuffer() on the wrapped response object.

public void
setBufferSize(int
the preferred buffer size
size
)

Implements jakarta.servlet.ServletResponse.setBufferSize.

The default behavior of this method is to call setBufferSize(int size) on the wrapped response object.

public void
setCharacterEncoding(String
a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets) or null
encoding
)

Implements jakarta.servlet.ServletResponse.setCharacterEncoding.

The default behavior of this method is to call setCharacterEncoding(String encoding) on the wrapped response object.

public void
setCharacterEncoding(Charset
a Charset instance representing the encoding to use or null
encoding
)

Overrides default jakarta.servlet.ServletResponse.setCharacterEncoding.

The default behavior of this method is to call setCharacterEncoding(Charset encoding) on the wrapped response object.

public void
setContentLength(int
an integer specifying the length of the content being returned to the client; sets the Content-Length header
len
)

Implements jakarta.servlet.ServletResponse.setContentLength.

The default behavior of this method is to call setContentLength(int len) on the wrapped response object.

public void
setContentLengthLong(long
a long specifying the length of the content being returned to the client; sets the Content-Length header
len
)

Implements jakarta.servlet.ServletResponse.setContentLengthLong.

The default behavior of this method is to call setContentLengthLong(long len) on the wrapped response object.

public void
setContentType(String
a String specifying the MIME type of the content or null
type
)

Implements jakarta.servlet.ServletResponse.setContentType.

The default behavior of this method is to call setContentType(String type) on the wrapped response object.

public void
setLocale(Locale
the locale of the response or {code @null}
loc
)

Implements jakarta.servlet.ServletResponse.setLocale.

The default behavior of this method is to call setLocale(Locale loc) on the wrapped response object.

public void
setResponse(ServletResponse
the ServletResponse to be installed
response
)

Sets the response being wrapped.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

responseback to summary
private ServletResponse response

Constructor Detail

ServletResponseWrapperback to summary
public ServletResponseWrapper(ServletResponse response)

Creates a ServletResponse adaptor wrapping the given response object.

Parameters
response:ServletResponse

the ServletResponse to be wrapped

Exceptions
IllegalArgumentException:
if the response is null.

Method Detail

flushBufferback to summary
public void flushBuffer() throws IOException

Implements jakarta.servlet.ServletResponse.flushBuffer.

The default behavior of this method is to call flushBuffer() on the wrapped response object.

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.ServletResponse.flushBuffer.

if the act of flushing the buffer cannot be completed.

getBufferSizeback to summary
public int getBufferSize()

Implements jakarta.servlet.ServletResponse.getBufferSize.

The default behavior of this method is to return getBufferSize() on the wrapped response object.

Returns:int

Doc from jakarta.servlet.ServletResponse.getBufferSize.

the actual buffer size used

Annotations
@Override
getCharacterEncodingback to summary
public String getCharacterEncoding()

Implements jakarta.servlet.ServletResponse.getCharacterEncoding.

The default behavior of this method is to return getCharacterEncoding() on the wrapped response object.

Returns:String

Doc from jakarta.servlet.ServletResponse.getCharacterEncoding.

a String specifying the name of the character encoding, for example, UTF-8

Annotations
@Override
getContentTypeback to summary
public String getContentType()

Implements jakarta.servlet.ServletResponse.getContentType.

The default behavior of this method is to return getContentType() on the wrapped response object.

Returns:String

Doc from jakarta.servlet.ServletResponse.getContentType.

a String specifying the content type, for example, text/html; charset=UTF-8, or null

Annotations
@Override
Since
Servlet 2.4
getLocaleback to summary
public Locale getLocale()

Implements jakarta.servlet.ServletResponse.getLocale.

The default behavior of this method is to return getLocale() on the wrapped response object.

Returns:Locale

Doc from jakarta.servlet.ServletResponse.getLocale.

the Locale for this response.

Annotations
@Override
getOutputStreamback to summary
public ServletOutputStream getOutputStream() throws IOException

Implements jakarta.servlet.ServletResponse.getOutputStream.

The default behavior of this method is to return getOutputStream() on the wrapped response object.

Returns:ServletOutputStream

Doc from jakarta.servlet.ServletResponse.getOutputStream.

a ServletOutputStream for writing binary data

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.ServletResponse.getOutputStream.

if an input or output exception occurred

getResponseback to summary
public ServletResponse getResponse()

Return the wrapped ServletResponse object.

Returns:ServletResponse

the wrapped ServletResponse

getWriterback to summary
public PrintWriter getWriter() throws IOException

Implements jakarta.servlet.ServletResponse.getWriter.

The default behavior of this method is to return getWriter() on the wrapped response object.

Returns:PrintWriter

Doc from jakarta.servlet.ServletResponse.getWriter.

a PrintWriter object that can return character data to the client

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.ServletResponse.getWriter.

if an input or output exception occurred

isCommittedback to summary
public boolean isCommitted()

Implements jakarta.servlet.ServletResponse.isCommitted.

The default behavior of this method is to return isCommitted() on the wrapped response object.

Returns:boolean

Doc from jakarta.servlet.ServletResponse.isCommitted.

a boolean indicating if the response has been committed

Annotations
@Override
isWrapperForback to summary
public boolean isWrapperFor(ServletResponse wrapped)

Checks (recursively) if this ServletResponseWrapper wraps the given ServletResponse instance.

Parameters
wrapped:ServletResponse

the ServletResponse instance to search for

Returns:boolean

true if this ServletResponseWrapper wraps the given ServletResponse instance, false otherwise

Since
Servlet 3.0
isWrapperForback to summary
public boolean isWrapperFor(Class<?> wrappedType)

Checks (recursively) if this ServletResponseWrapper wraps a ServletResponse of the given class type.

Parameters
wrappedType:Class<?>

the ServletResponse class type to search for

Returns:boolean

true if this ServletResponseWrapper wraps a ServletResponse of the given class type, false otherwise

Exceptions
IllegalArgumentException:
if the given class does not implement ServletResponse
Since
Servlet 3.0
resetback to summary
public void reset()

Implements jakarta.servlet.ServletResponse.reset.

The default behavior of this method is to call reset() on the wrapped response object.

Annotations
@Override
resetBufferback to summary
public void resetBuffer()

Implements jakarta.servlet.ServletResponse.resetBuffer.

The default behavior of this method is to call resetBuffer() on the wrapped response object.

Annotations
@Override
setBufferSizeback to summary
public void setBufferSize(int size)

Implements jakarta.servlet.ServletResponse.setBufferSize.

The default behavior of this method is to call setBufferSize(int size) on the wrapped response object.

Parameters
size:int

Doc from jakarta.servlet.ServletResponse.setBufferSize.

the preferred buffer size

Annotations
@Override
setCharacterEncodingback to summary
public void setCharacterEncoding(String encoding)

Implements jakarta.servlet.ServletResponse.setCharacterEncoding.

The default behavior of this method is to call setCharacterEncoding(String encoding) on the wrapped response object.

Parameters
encoding:String

Doc from jakarta.servlet.ServletResponse.setCharacterEncoding.

a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets) or null

Annotations
@Override
Since
Servlet 2.4
setCharacterEncodingback to summary
public void setCharacterEncoding(Charset encoding)

Overrides default jakarta.servlet.ServletResponse.setCharacterEncoding.

The default behavior of this method is to call setCharacterEncoding(Charset encoding) on the wrapped response object.

Parameters
encoding:Charset

Doc from jakarta.servlet.ServletResponse.setCharacterEncoding.

a Charset instance representing the encoding to use or null

Annotations
@Override
Since
Servlet 6.1
setContentLengthback to summary
public void setContentLength(int len)

Implements jakarta.servlet.ServletResponse.setContentLength.

The default behavior of this method is to call setContentLength(int len) on the wrapped response object.

Parameters
len:int

Doc from jakarta.servlet.ServletResponse.setContentLength.

an integer specifying the length of the content being returned to the client; sets the Content-Length header

Annotations
@Override
setContentLengthLongback to summary
public void setContentLengthLong(long len)

Implements jakarta.servlet.ServletResponse.setContentLengthLong.

The default behavior of this method is to call setContentLengthLong(long len) on the wrapped response object.

Parameters
len:long

Doc from jakarta.servlet.ServletResponse.setContentLengthLong.

a long specifying the length of the content being returned to the client; sets the Content-Length header

Annotations
@Override
Since
Servlet 3.1
setContentTypeback to summary
public void setContentType(String type)

Implements jakarta.servlet.ServletResponse.setContentType.

The default behavior of this method is to call setContentType(String type) on the wrapped response object.

Parameters
type:String

Doc from jakarta.servlet.ServletResponse.setContentType.

a String specifying the MIME type of the content or null

Annotations
@Override
setLocaleback to summary
public void setLocale(Locale loc)

Implements jakarta.servlet.ServletResponse.setLocale.

The default behavior of this method is to call setLocale(Locale loc) on the wrapped response object.

Parameters
loc:Locale

Doc from jakarta.servlet.ServletResponse.setLocale.

the locale of the response or {code @null}

Annotations
@Override
setResponseback to summary
public void setResponse(ServletResponse response)

Sets the response being wrapped.

Parameters
response:ServletResponse

the ServletResponse to be installed

Exceptions
IllegalArgumentException:
if the response is null.