Http11OutputBuffer (Apache Tomcat 11.0.24 API Documentation)
Description: declaration: package: org.apache.coyote.http11, class: Http11OutputBuffer

# Class Http11OutputBuffer

java.lang.Object
org.apache.coyote.http11.Http11OutputBuffer

All Implemented Interfaces:
  `HttpOutputBuffer, OutputBuffer`

public class Http11OutputBuffer extends Object implements HttpOutputBuffer
Provides buffering for the HTTP headers (allowing responses to be reset before they have been committed) and the link to the Socket for writing the headers (once committed) and the response body. Note that buffering of the response body happens at a higher level.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected class`
  `Http11OutputBuffer.SocketOutputBuffer`
  This class is an output buffer which will write data to a socket.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected OutputFilter[]`
  `activeFilters`
  Active filters for the current request.
  `protected long`
  `byteCount`
  Bytes written to client for the current request
  `protected OutputFilter[]`
  `filterLibrary`
  Filter library for processing the response body.
  `protected final ByteBuffer`
  `headerBuffer`
  The buffer used for header composition.
  `protected int`
  `lastActiveFilter`
  Index of the last active filter.
  `protected HttpOutputBuffer`
  `outputStreamOutputBuffer`
  Underlying output buffer.
  `protected final Response`
  `response`
  Associated Coyote response.
  `protected boolean`
  `responseFinished`
  Finished flag.
  `protected static final StringManager`
  `sm`
  The string manager for this package.
  `protected SocketWrapperBase<?>`
  `socketWrapper`
  Wrapper for socket where data will be written to.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Http11OutputBuffer(Response response, int headerBufferSize)`
  Constructs a new Http11OutputBuffer.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addActiveFilter(OutputFilter filter)`
  Add an output filter to the active filters for the current response.
  `void`
  `addFilter(OutputFilter filter)`
  Add an output filter to the filter library.
  `protected void`
  `commit()`
  Commit the response.
  `int`
  `doWrite(ByteBuffer chunk)`
  Write the given data to the response.
  `void`
  `end()`
  Finish writing the current response.
  `void`
  `endHeaders()`
  End the header block.
  `void`
  `flush()`
  Flushes any unwritten data to the client.
  `protected boolean`
  `flushBuffer(boolean block)`
  Writes any remaining buffered data.
  `long`
  `getBytesWritten()`
  Bytes written to the underlying socket.
  `OutputFilter[]`
  `getFilters()`
  Get filters.
  `boolean`
  `hasDataToWrite()`
  Check if there is data waiting to be written to the socket.
  `void`
  `init(SocketWrapperBase<?> socketWrapper)`
  Initialize the output buffer with the socket wrapper.
  `protected final boolean`
  `isBlocking()`
  Is standard Servlet blocking IO being used for output?
  `protected final boolean`
  `isReady()`
  Check if the socket is ready for writing.
  `void`
  `nextRequest()`
  End processing of current HTTP request.
  `void`
  `recycle()`
  Recycle the output buffer.
  `void`
  `registerWriteInterest()`
  Register interest in write events on the socket.
  `void`
  `sendAck()`
  Send a 100-continue acknowledgment to the client.
  `void`
  `sendHeader(MessageBytes name, MessageBytes value)`
  Send a header.
  `void`
  `sendStatus(int status)`
  Send the response status line.
  `void`
  `write(byte[] b)`
  This method will write the contents of the specified byte buffer to the output stream, without filtering.
  `protected void`
  `writeHeaders()`
  Write the buffered headers to the socket.

  ### Methods inherited from class Object

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

- ## Field Details

  - ### sm

    protected static final StringManager sm
    The string manager for this package.

  - ### response

    protected final Response response
    Associated Coyote response.

  - ### responseFinished

    protected boolean responseFinished
    Finished flag.

  - ### headerBuffer

    protected final ByteBuffer headerBuffer
    The buffer used for header composition.

  - ### filterLibrary

    protected OutputFilter[] filterLibrary
    Filter library for processing the response body.

  - ### activeFilters

    protected OutputFilter[] activeFilters
    Active filters for the current request.

  - ### lastActiveFilter

    protected int lastActiveFilter
    Index of the last active filter.

  - ### outputStreamOutputBuffer

    protected HttpOutputBuffer outputStreamOutputBuffer
    Underlying output buffer.

  - ### socketWrapper

    protected SocketWrapperBase<?> socketWrapper
    Wrapper for socket where data will be written to.

  - ### byteCount

    protected long byteCount
    Bytes written to client for the current request

- ## Constructor Details

  - ### Http11OutputBuffer

    protected Http11OutputBuffer(Response response, int headerBufferSize)
    Constructs a new Http11OutputBuffer.
    Parameters:
      `response` - the Coyote response
      `headerBufferSize` - the maximum size of the header buffer

- ## Method Details

  - ### addFilter

    public void addFilter(OutputFilter filter)
    Add an output filter to the filter library. Note that calling this method resets the currently active filters to none.
    Parameters:
      `filter` - The filter to add

  - ### getFilters

    public OutputFilter[] getFilters()
    Get filters.
    Returns:
      The current filter library containing all possible filters

  - ### addActiveFilter

    public void addActiveFilter(OutputFilter filter)
    Add an output filter to the active filters for the current response.

    The filter does not have to be present in `getFilters()`.

    A filter can only be added to a response once. If the filter has already been added to this response then this method will be a NO-OP.

    Parameters:
      `filter` - The filter to add

  - ### doWrite

    public int doWrite(ByteBuffer chunk) throws IOException
    Description copied from interface: `OutputBuffer`
    Write the given data to the response. The caller owns the chunks.
    Specified by:
      `doWrite` in interface `OutputBuffer`
    Parameters:
      `chunk` - data to write
    Returns:
      The number of bytes written which may be less than available in the input chunk
    Throws:
      `IOException` - an underlying I/O error occurred

  - ### getBytesWritten

    public long getBytesWritten()
    Description copied from interface: `OutputBuffer`
    Bytes written to the underlying socket. This includes the effects of chunking, compression, etc.
    Specified by:
      `getBytesWritten` in interface `OutputBuffer`
    Returns:
      Bytes written for the current request

  - ### flush

    public void flush() throws IOException
    Description copied from interface: `HttpOutputBuffer`
    Flushes any unwritten data to the client.
    Specified by:
      `flush` in interface `HttpOutputBuffer`
    Throws:
      `IOException` - If an I/O error occurs while flushing

  - ### end

    public void end() throws IOException
    Description copied from interface: `HttpOutputBuffer`
    Finish writing the current response. It is acceptable to write extra bytes using `OutputBuffer.doWrite(java.nio.ByteBuffer)` during the execution of this method.
    Specified by:
      `end` in interface `HttpOutputBuffer`
    Throws:
      `IOException` - If an I/O error occurs while writing to the client

  - ### recycle

    public void recycle()
    Recycle the output buffer. This should be called when closing the connection.

  - ### nextRequest

    public void nextRequest()
    End processing of current HTTP request. Note: All bytes of the current request should have been already consumed. This method only resets all the pointers so that we are ready to parse the next HTTP request.

  - ### init

    public void init(SocketWrapperBase<?> socketWrapper)
    Initialize the output buffer with the socket wrapper.
    Parameters:
      `socketWrapper` - the socket wrapper

  - ### sendAck

    public void sendAck() throws IOException
    Send a 100-continue acknowledgment to the client.
    Throws:
      `IOException` - if an I/O error occurs

  - ### commit

    protected void commit() throws IOException
    Commit the response.
    Throws:
      `IOException` - an underlying I/O error occurred

  - ### writeHeaders

    protected void writeHeaders() throws IOException
    Write the buffered headers to the socket.
    Throws:
      `IOException` - if an I/O error occurs

  - ### sendStatus

    public void sendStatus(int status)
    Send the response status line.
    Parameters:
      `status` - The HTTP status code to include in the status line

  - ### sendHeader

    public void sendHeader(MessageBytes name, MessageBytes value)
    Send a header.
    Parameters:
      `name` - Header name
      `value` - Header value

  - ### endHeaders

    public void endHeaders()
    End the header block.

  - ### write

    public void write(byte[] b)
    This method will write the contents of the specified byte buffer to the output stream, without filtering. This method is meant to be used to write the response header.
    Parameters:
      `b` - data to be written

  - ### flushBuffer

    protected boolean flushBuffer(boolean block) throws IOException
    Writes any remaining buffered data.
    Parameters:
      `block` - Should this method block until the buffer is empty
    Returns:
      `true` if data remains in the buffer (which can only happen in non-blocking mode) else `false`.
    Throws:
      `IOException` - Error writing data

  - ### isBlocking

    protected final boolean isBlocking()
    Is standard Servlet blocking IO being used for output?
    Returns:
      `true` if this is blocking IO

  - ### isReady

    protected final boolean isReady()
    Check if the socket is ready for writing.
    Returns:
      `true` if the socket is ready for writing

  - ### hasDataToWrite

    public boolean hasDataToWrite()
    Check if there is data waiting to be written to the socket.
    Returns:
      `true` if there is data waiting to be written

  - ### registerWriteInterest

    public void registerWriteInterest()
    Register interest in write events on the socket.