Top Description Inners Fields Constructors Methods
org.springframework.web.util

public Class ContentCachingResponseWrapper

extends HttpServletResponseWrapper
Class Inheritance
Known Direct Subclasses
org.springframework.web.filter.ShallowEtagHeaderFilter.ConditionalContentCachingResponseWrapper
Imports
java.io.IOException, .InputStream, .OutputStreamWriter, .PrintWriter, .UnsupportedEncodingException, java.util.ArrayList, .Collection, .Collections, .List, jakarta.servlet.ServletOutputStream, .WriteListener, jakarta.servlet.http.HttpServletResponse, .HttpServletResponseWrapper, org.springframework.http.HttpHeaders, org.springframework.lang.Nullable, org.springframework.util.FastByteArrayOutputStream

jakarta.servlet.http.HttpServletResponse wrapper that caches all content written to the output stream and writer, and allows this content to be retrieved via a byte array.

Used e.g. by org.springframework.web.filter.ShallowEtagHeaderFilter.

Author
Juergen Hoeller
Since
4.1.3
See Also
ContentCachingRequestWrapper

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private final FastByteArrayOutputStream
private Integer
private String
private ServletOutputStream
private PrintWriter

Constructor Summary

AccessConstructor and Description
public
ContentCachingResponseWrapper(HttpServletResponse
the original servlet response
response
)

Create a new ContentCachingResponseWrapper for the given servlet response.

Method Summary

Modifier and TypeMethod and Description
public void
addHeader(String
the name of the header
name
,
String
the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)
value
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.addHeader.

Implements jakarta.servlet.http.HttpServletResponse.addHeader.

The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object.

public void
addIntHeader(String
the name of the header
name
,
int
the assigned integer value
value
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.addIntHeader.

Implements jakarta.servlet.http.HttpServletResponse.addIntHeader.

The default behavior of this method is to call addIntHeader(String name, int value) on the wrapped response object.

public boolean
containsHeader(String
the header name
name
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.containsHeader.

Implements jakarta.servlet.http.HttpServletResponse.containsHeader.

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

public void
copyBodyToResponse()

Copy the complete cached body content to the response.

protected void
copyBodyToResponse(boolean
whether to set a corresponding content length for the complete cached body content
complete
)

Copy the cached body content to the response.

public void
flushBuffer()

Overrides jakarta.servlet.ServletResponseWrapper.flushBuffer.

Implements jakarta.servlet.ServletResponse.flushBuffer.

Forces any content in the buffer to be written to the client.

public byte[]
getContentAsByteArray()

Return the cached response content as a byte array.

public InputStream
getContentInputStream()

Return an InputStream to the cached content.

public int
getContentSize()

Return the current size of the cached content.

public String
getContentType()

Overrides jakarta.servlet.ServletResponseWrapper.getContentType.

Implements jakarta.servlet.ServletResponse.getContentType.

Returns the content type used for the MIME body sent in this response.

public String
getHeader(String
Header name to look up
name
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.getHeader.

Implements jakarta.servlet.http.HttpServletResponse.getHeader.

Return the value for the specified header, or null if this header has not been set.

public Collection<String>
public Collection<String>
getHeaders(String
Header name to look up
name
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.getHeaders.

Implements jakarta.servlet.http.HttpServletResponse.getHeaders.

Return a Collection of all the header values associated with the specified header name.

public ServletOutputStream
public PrintWriter
getWriter()

Overrides jakarta.servlet.ServletResponseWrapper.getWriter.

Implements jakarta.servlet.ServletResponse.getWriter.

Returns a PrintWriter object that can send character text to the client.

public void
reset()

Overrides jakarta.servlet.ServletResponseWrapper.reset.

Implements jakarta.servlet.ServletResponse.reset.

Clears any data that exists in the buffer as well as the status code and headers.

public void
resetBuffer()

Overrides jakarta.servlet.ServletResponseWrapper.resetBuffer.

Implements jakarta.servlet.ServletResponse.resetBuffer.

Clears the content of the underlying buffer in the response without clearing headers or status code.

public void
sendError(int
the error status code
sc
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.sendError.

Implements jakarta.servlet.http.HttpServletResponse.sendError.

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

public void
sendError(int
the error status code
sc
,
String
the descriptive message
msg
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.sendError.

Implements jakarta.servlet.http.HttpServletResponse.sendError.

The default behavior of this method is to call sendError(int sc, String msg) on the wrapped response object.

public void
sendRedirect(String
the redirect location URL (may be absolute or relative)
location
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.sendRedirect.

Implements jakarta.servlet.http.HttpServletResponse.sendRedirect.

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

public void
setBufferSize(int
the preferred buffer size
size
)

Overrides jakarta.servlet.ServletResponseWrapper.setBufferSize.

Implements jakarta.servlet.ServletResponse.setBufferSize.

Sets the preferred buffer size for the body of the response.

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

Overrides jakarta.servlet.ServletResponseWrapper.setContentLength.

Implements jakarta.servlet.ServletResponse.setContentLength.

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.

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

Overrides jakarta.servlet.ServletResponseWrapper.setContentLengthLong.

Implements jakarta.servlet.ServletResponse.setContentLengthLong.

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.

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

Overrides jakarta.servlet.ServletResponseWrapper.setContentType.

Implements jakarta.servlet.ServletResponse.setContentType.

Sets the content type of the response being sent to the client, if the response has not been committed yet.

public void
setHeader(String
the name of the header
name
,
String
the header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)
value
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.setHeader.

Implements jakarta.servlet.http.HttpServletResponse.setHeader.

The default behavior of this method is to return setHeader(String name, String value) on the wrapped response object.

public void
setIntHeader(String
the name of the header
name
,
int
the assigned integer value
value
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.setIntHeader.

Implements jakarta.servlet.http.HttpServletResponse.setIntHeader.

The default behavior of this method is to call setIntHeader(String name, int value) on the wrapped response object.

Inherited from jakarta.servlet.http.HttpServletResponseWrapper:
addCookieaddDateHeaderencodeRedirectURLencodeURLgetStatusgetTrailerFieldssetDateHeadersetStatussetTrailerFields

Field Detail

contentback to summary
private final FastByteArrayOutputStream content
contentLengthback to summary
private Integer contentLength
Annotations
@Nullable
contentTypeback to summary
private String contentType
Annotations
@Nullable
outputStreamback to summary
private ServletOutputStream outputStream
Annotations
@Nullable
writerback to summary
private PrintWriter writer
Annotations
@Nullable

Constructor Detail

ContentCachingResponseWrapperback to summary
public ContentCachingResponseWrapper(HttpServletResponse response)

Create a new ContentCachingResponseWrapper for the given servlet response.

Parameters
response:HttpServletResponse

the original servlet response

Method Detail

addHeaderback to summary
public void addHeader(String name, String value)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.addHeader.

Implements jakarta.servlet.http.HttpServletResponse.addHeader.

Doc from jakarta.servlet.http.HttpServletResponseWrapper.addHeader.

The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.addHeader.

the name of the header

value:String

Doc from jakarta.servlet.http.HttpServletResponse.addHeader.

the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)

Annotations
@Override
addIntHeaderback to summary
public void addIntHeader(String name, int value)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.addIntHeader.

Implements jakarta.servlet.http.HttpServletResponse.addIntHeader.

Doc from jakarta.servlet.http.HttpServletResponseWrapper.addIntHeader.

The default behavior of this method is to call addIntHeader(String name, int value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.addIntHeader.

the name of the header

value:int

Doc from jakarta.servlet.http.HttpServletResponse.addIntHeader.

the assigned integer value

Annotations
@Override
containsHeaderback to summary
public boolean containsHeader(String name)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.containsHeader.

Implements jakarta.servlet.http.HttpServletResponse.containsHeader.

Doc from jakarta.servlet.http.HttpServletResponseWrapper.containsHeader.

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

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.containsHeader.

the header name

Returns:boolean

Doc from jakarta.servlet.http.HttpServletResponse.containsHeader.

true if the named response header has already been set; false otherwise

Annotations
@Override
copyBodyToResponseback to summary
public void copyBodyToResponse() throws IOException

Copy the complete cached body content to the response.

Since
4.2
copyBodyToResponseback to summary
protected void copyBodyToResponse(boolean complete) throws IOException

Copy the cached body content to the response.

Parameters
complete:boolean

whether to set a corresponding content length for the complete cached body content

Since
4.2
flushBufferback to summary
public void flushBuffer() throws IOException

Overrides jakarta.servlet.ServletResponseWrapper.flushBuffer.

Implements jakarta.servlet.ServletResponse.flushBuffer.

Doc from jakarta.servlet.ServletResponse.flushBuffer.

Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.

Annotations
@Override
Exceptions
IOException:
if an I/O occurs during the flushing of the response
getContentAsByteArrayback to summary
public byte[] getContentAsByteArray()

Return the cached response content as a byte array.

getContentInputStreamback to summary
public InputStream getContentInputStream()

Return an InputStream to the cached content.

Since
4.2
getContentSizeback to summary
public int getContentSize()

Return the current size of the cached content.

Since
4.2
getContentTypeback to summary
public String getContentType()

Overrides jakarta.servlet.ServletResponseWrapper.getContentType.

Implements jakarta.servlet.ServletResponse.getContentType.

Doc from jakarta.servlet.ServletResponse.getContentType.

Returns the content type used for the MIME body sent in this response. The content type proper must have been specified using setContentType before the response is committed. If no content type has been specified, this method returns null. If a content type has been specified and a character encoding has been explicitly or implicitly specified as described in getCharacterEncoding, the charset parameter is included in the string returned. If no character encoding has been specified, the charset parameter is omitted.

Returns:String

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

Annotations
@Override
@Nullable
getHeaderback to summary
public String getHeader(String name)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.getHeader.

Implements jakarta.servlet.http.HttpServletResponse.getHeader.

Doc from jakarta.servlet.http.HttpServletResponseWrapper.getHeader.

Return the value for the specified header, or null if this header has not been set. If more than one value was added for this name, only the first is returned; use getHeaders(String) to retrieve all of them.

The default implementation is to call HttpServletResponse#getHeader(String) on the wrapped HttpServletResponse.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.getHeader.

Header name to look up

Returns:String

Doc from jakarta.servlet.http.HttpServletResponse.getHeader.

The first value for the specified header. This is the raw value so if multiple values are specified in the first header then they will be returned as a single header value .

Annotations
@Override
@Nullable
getHeaderNamesback to summary
public Collection<String> getHeaderNames()

Overrides jakarta.servlet.http.HttpServletResponseWrapper.getHeaderNames.

Implements jakarta.servlet.http.HttpServletResponse.getHeaderNames.

Doc from jakarta.servlet.http.HttpServletResponseWrapper.getHeaderNames.

Get the header names set for this HTTP response.

The default implementation is to call HttpServletResponse#getHeaderNames() on the wrapped HttpServletResponse.

Returns:Collection<String>

Doc from jakarta.servlet.http.HttpServletResponse.getHeaderNames.

The header names set for this HTTP response.

Annotations
@Override
getHeadersback to summary
public Collection<String> getHeaders(String name)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.getHeaders.

Implements jakarta.servlet.http.HttpServletResponse.getHeaders.

Doc from jakarta.servlet.http.HttpServletResponseWrapper.getHeaders.

Return a Collection of all the header values associated with the specified header name.

The default implementation is to call HttpServletResponse#getHeaders(String) on the wrapped HttpServletResponse.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.getHeaders.

Header name to look up

Returns:Collection<String>

Doc from jakarta.servlet.http.HttpServletResponse.getHeaders.

The values for the specified header. These are the raw values so if multiple values are specified in a single header that will be returned as a single header value.

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

Overrides jakarta.servlet.ServletResponseWrapper.getOutputStream.

Implements jakarta.servlet.ServletResponse.getOutputStream.

Doc from jakarta.servlet.ServletResponse.getOutputStream.

Returns a ServletOutputStream suitable for writing binary data in the response. The servlet container does not encode the binary data.

Calling flush() on the ServletOutputStream commits the response. Either this method or getWriter may be called to write the body, not both.

Returns:ServletOutputStream

a ServletOutputStream for writing binary data

Annotations
@Override
Exceptions
IOException:
if an input or output exception occurred
getWriterback to summary
public PrintWriter getWriter() throws IOException

Overrides jakarta.servlet.ServletResponseWrapper.getWriter.

Implements jakarta.servlet.ServletResponse.getWriter.

Doc from jakarta.servlet.ServletResponse.getWriter.

Returns a PrintWriter object that can send character text to the client. The PrintWriter uses the character encoding returned by getCharacterEncoding. If the response's character encoding has not been specified as described in getCharacterEncoding (i.e., the method just returns the default value ISO-8859-1), getWriter updates it to ISO-8859-1.

Calling flush() on the PrintWriter commits the response.

Either this method or getOutputStream may be called to write the body, not both.

Returns:PrintWriter

a PrintWriter object that can return character data to the client

Annotations
@Override
Exceptions
IOException:
if an input or output exception occurred
resetback to summary
public void reset()

Overrides jakarta.servlet.ServletResponseWrapper.reset.

Implements jakarta.servlet.ServletResponse.reset.

Doc from jakarta.servlet.ServletResponse.reset.

Clears any data that exists in the buffer as well as the status code and headers. If the response has been committed, this method throws an IllegalStateException.

Annotations
@Override
resetBufferback to summary
public void resetBuffer()

Overrides jakarta.servlet.ServletResponseWrapper.resetBuffer.

Implements jakarta.servlet.ServletResponse.resetBuffer.

Doc from jakarta.servlet.ServletResponse.resetBuffer.

Clears the content of the underlying buffer in the response without clearing headers or status code. If the response has been committed, this method throws an IllegalStateException.

Annotations
@Override
sendErrorback to summary
public void sendError(int sc) throws IOException

Overrides jakarta.servlet.http.HttpServletResponseWrapper.sendError.

Implements jakarta.servlet.http.HttpServletResponse.sendError.

Doc from jakarta.servlet.http.HttpServletResponseWrapper.sendError.

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

Parameters
sc:int

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

the error status code

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

If an input or output exception occurs

sendErrorback to summary
public void sendError(int sc, String msg) throws IOException

Overrides jakarta.servlet.http.HttpServletResponseWrapper.sendError.

Implements jakarta.servlet.http.HttpServletResponse.sendError.

Doc from jakarta.servlet.http.HttpServletResponseWrapper.sendError.

The default behavior of this method is to call sendError(int sc, String msg) on the wrapped response object.

Parameters
sc:int

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

the error status code

msg:String

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

the descriptive message

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

If an input or output exception occurs

sendRedirectback to summary
public void sendRedirect(String location) throws IOException

Overrides jakarta.servlet.http.HttpServletResponseWrapper.sendRedirect.

Implements jakarta.servlet.http.HttpServletResponse.sendRedirect.

Doc from jakarta.servlet.http.HttpServletResponseWrapper.sendRedirect.

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

Parameters
location:String

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

the redirect location URL (may be absolute or relative)

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

If an input or output exception occurs

setBufferSizeback to summary
public void setBufferSize(int size)

Overrides jakarta.servlet.ServletResponseWrapper.setBufferSize.

Implements jakarta.servlet.ServletResponse.setBufferSize.

Doc from jakarta.servlet.ServletResponse.setBufferSize.

Sets the preferred buffer size for the body of the response. The servlet container will use a buffer at least as large as the size requested. The actual buffer size used can be found using getBufferSize.

A larger buffer allows more content to be written before anything is actually sent, thus providing the servlet with more time to set appropriate status codes and headers. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.

This method must be called before any response body content is written; if content has been written or the response object has been committed, this method throws an IllegalStateException.

Parameters
size:int

the preferred buffer size

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

Overrides jakarta.servlet.ServletResponseWrapper.setContentLength.

Implements jakarta.servlet.ServletResponse.setContentLength.

Doc from jakarta.servlet.ServletResponse.setContentLength.

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.

Parameters
len:int

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)

Overrides jakarta.servlet.ServletResponseWrapper.setContentLengthLong.

Implements jakarta.servlet.ServletResponse.setContentLengthLong.

Doc from jakarta.servlet.ServletResponse.setContentLengthLong.

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.

Parameters
len:long

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

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

Overrides jakarta.servlet.ServletResponseWrapper.setContentType.

Implements jakarta.servlet.ServletResponse.setContentType.

Doc from jakarta.servlet.ServletResponse.setContentType.

Sets the content type of the response being sent to the client, if the response has not been committed yet. The given content type may include a character encoding specification, for example, text/html;charset=UTF-8. The response's character encoding is only set from the given content type if this method is called before getWriter is called.

This method may be called repeatedly to change content type and character encoding. This method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after getWriter has been called or after the response has been committed.

Containers must communicate the content type and the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the Content-Type header is used.

Parameters
type:String

a String specifying the MIME type of the content

Annotations
@Override
setHeaderback to summary
public void setHeader(String name, String value)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.setHeader.

Implements jakarta.servlet.http.HttpServletResponse.setHeader.

Doc from jakarta.servlet.http.HttpServletResponseWrapper.setHeader.

The default behavior of this method is to return setHeader(String name, String value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.setHeader.

the name of the header

value:String

Doc from jakarta.servlet.http.HttpServletResponse.setHeader.

the header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)

Annotations
@Override
setIntHeaderback to summary
public void setIntHeader(String name, int value)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.setIntHeader.

Implements jakarta.servlet.http.HttpServletResponse.setIntHeader.

Doc from jakarta.servlet.http.HttpServletResponseWrapper.setIntHeader.

The default behavior of this method is to call setIntHeader(String name, int value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.setIntHeader.

the name of the header

value:int

Doc from jakarta.servlet.http.HttpServletResponse.setIntHeader.

the assigned integer value

Annotations
@Override
org.springframework.web.util back to summary

private Class ContentCachingResponseWrapper.ResponsePrintWriter

extends PrintWriter
Class Inheritance

Field Summary

Inherited from java.io.PrintWriter:
out

Constructor Summary

AccessConstructor and Description
public
ResponsePrintWriter(String characterEncoding)

Method Summary

Modifier and TypeMethod and Description
public void
write(char[]
Array of characters
buf
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Overrides java.io.PrintWriter.write.

Writes A Portion of an array of characters.

public void
write(String
A String
s
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Overrides java.io.PrintWriter.write.

Writes a portion of a string.

public void
write(int
int specifying a character to be written.
c
)

Overrides java.io.PrintWriter.write.

Writes a single character.

Inherited from java.io.PrintWriter:
appendappendappendcheckErrorclearErrorcloseflushformatformatprintprintprintprintprintprintprintprintprintprintfprintfprintlnprintlnprintlnprintlnprintlnprintlnprintlnprintlnprintlnprintlnsetErrorwritewrite

Constructor Detail

ResponsePrintWriterback to summary
public ResponsePrintWriter(String characterEncoding) throws UnsupportedEncodingException

Method Detail

writeback to summary
public void write(char[] buf, int off, int len)

Overrides java.io.PrintWriter.write.

Doc from java.io.PrintWriter.write.

Writes A Portion of an array of characters.

Parameters
buf:char[]

Array of characters

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Annotations
@Override
writeback to summary
public void write(String s, int off, int len)

Overrides java.io.PrintWriter.write.

Doc from java.io.PrintWriter.write.

Writes a portion of a string.

Parameters
s:String

A String

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Annotations
@Override
writeback to summary
public void write(int c)

Overrides java.io.PrintWriter.write.

Doc from java.io.PrintWriter.write.

Writes a single character.

Parameters
c:int

int specifying a character to be written.

Annotations
@Override
org.springframework.web.util back to summary

private Class ContentCachingResponseWrapper.ResponseServletOutputStream

extends ServletOutputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ServletOutputStream

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
isReady()

Implements abstract jakarta.servlet.ServletOutputStream.isReady.

Checks if a non-blocking write will succeed.

public void
setWriteListener(WriteListener
The non-blocking IO write listener
writeListener
)

Implements abstract jakarta.servlet.ServletOutputStream.setWriteListener.

Sets the WriteListener for this ServletOutputStream and thereby switches to non-blocking IO.

public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Inherited from jakarta.servlet.ServletOutputStream:
printprintprintprintprintprintprintprintlnprintlnprintlnprintlnprintlnprintlnprintlnprintln

Field Detail

osback to summary
private final ServletOutputStream os

Constructor Detail

ResponseServletOutputStreamback to summary
public ResponseServletOutputStream(ServletOutputStream os)

Method Detail

isReadyback to summary
public boolean isReady()

Implements abstract jakarta.servlet.ServletOutputStream.isReady.

Doc from jakarta.servlet.ServletOutputStream.isReady.

Checks if a non-blocking write will succeed. If this returns false, it will cause a callback to WriteListener#onWritePossible() when the buffer has emptied. If this method returns false no further data must be written until the container calls WriteListener#onWritePossible().

Returns:boolean

true if data can be written, else false

Annotations
@Override
setWriteListenerback to summary
public void setWriteListener(WriteListener writeListener)

Implements abstract jakarta.servlet.ServletOutputStream.setWriteListener.

Doc from jakarta.servlet.ServletOutputStream.setWriteListener.

Sets the WriteListener for this ServletOutputStream and thereby switches to non-blocking IO. It is only valid to switch to non-blocking IO within async processing or HTTP upgrade processing.

Parameters
writeListener:WriteListener

The non-blocking IO write listener

Annotations
@Override
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.