## org.apache.coyote.http11
Class InternalOutputBuffer

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

All Implemented Interfaces:
  ByteChunk.ByteOutputChannel, OutputBuffer

public class InternalOutputBuffer
extends java.lang.Object
implements OutputBuffer, ByteChunk.ByteOutputChannel

Output buffer.

Author:
  Remy Maucherat

Nested Class Summary
`protected class` `InternalOutputBuffer.OutputStreamOutputBuffer` This class is an output buffer which will write data to an output stream.

Field Summary
`protected OutputFilter[]` `activeFilters` Active filter (which is actually the top of the pipeline).
`protected byte[]` `buf` Pointer to the current read buffer.
`protected boolean` `committed` Committed flag.
`protected OutputFilter[]` `filterLibrary` Filter library.
`protected boolean` `finished` Finished flag.
`protected byte[]` `headerBuffer` HTTP header buffer.
`protected MimeHeaders` `headers` Headers of the associated request.
`protected int` `lastActiveFilter` Index of the last active filter.
`protected java.io.OutputStream` `outputStream` Underlying output stream.
`protected OutputBuffer` `outputStreamOutputBuffer` Underlying output buffer.
`protected int` `pos` Position in the buffer.
`protected Response` `response` Associated Coyote response.
`protected static StringManager` `sm` The string manager for this package.
`protected ByteChunk` `socketBuffer` Socket buffer.
`protected boolean` `useSocketBuffer` Socket buffer (extra buffering to reduce number of packets sent).

Constructor Summary
`InternalOutputBuffer(Response response)` Default constructor.
`InternalOutputBuffer(Response response, int headerBufferSize)` Alternate constructor.

Method Summary
`void` `addActiveFilter(OutputFilter filter)` Add an output filter to the filter library.
`void` `addFilter(OutputFilter filter)` Add an output filter to the filter library.
`void` `clearFilters()` Clear filters.
`protected void` `commit()` Commit the response.
`int` `doWrite(ByteChunk chunk, Response res)` Write the contents of a byte chunk.
`void` `endHeaders()` End the header block.
`void` `endRequest()` End request.
`void` `flush()` Flush the response.
`OutputFilter[]` `getFilters()` Get filters.
`java.io.OutputStream` `getOutputStream()` Get the underlying socket output stream.
`void` `nextRequest()` End processing of current HTTP request.
`void` `realWriteBytes(byte[] cbuf, int off, int len)` Callback to write data from the buffer.
`void` `recycle()` Recycle the output buffer.
`void` `reset()` Reset current response.
`void` `sendAck()` Send an acknoledgement.
`void` `sendHeader(ByteChunk name, ByteChunk value)` Send a header.
`void` `sendHeader(MessageBytes name, MessageBytes value)` Send a header.
`void` `sendHeader(java.lang.String name, java.lang.String value)` Send a header.
`void` `sendStatus()` Send the response status line.
`void` `setOutputStream(java.io.OutputStream outputStream)` Set the underlying socket output stream.
`void` `setSocketBuffer(int socketBufferSize)` Set the socket buffer size.
`protected void` `write(byte[] b)` This method will write the contents of the specyfied byte buffer to the output stream, without filtering.
`protected void` `write(ByteChunk bc)` This method will write the contents of the specyfied message bytes buffer to the output stream, without filtering.
`protected void` `write(int i)` This method will print the specified integer to the output stream, without filtering.
`protected void` `write(MessageBytes mb)` This method will write the contents of the specyfied message bytes buffer to the output stream, without filtering.
`protected void` `write(java.lang.String s)` This method will write the contents of the specyfied String to the output stream, without filtering.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### sm

    protected static StringManager sm

  The string manager for this package.

### response

    protected Response response

  Associated Coyote response.

### headers

    protected MimeHeaders headers

  Headers of the associated request.

### committed

    protected boolean committed

  Committed flag.

### finished

    protected boolean finished

  Finished flag.

### buf

    protected byte[] buf

  Pointer to the current read buffer.

### pos

    protected int pos

  Position in the buffer.

### headerBuffer

    protected byte[] headerBuffer

  HTTP header buffer.

### outputStream

    protected java.io.OutputStream outputStream

  Underlying output stream.

### outputStreamOutputBuffer

    protected OutputBuffer outputStreamOutputBuffer

  Underlying output buffer.

### filterLibrary

    protected OutputFilter[] filterLibrary

  Filter library. Note: Filter[0] is always the "chunked" filter.

### activeFilters

    protected OutputFilter[] activeFilters

  Active filter (which is actually the top of the pipeline).

### lastActiveFilter

    protected int lastActiveFilter

  Index of the last active filter.

### socketBuffer

    protected ByteChunk socketBuffer

  Socket buffer.

### useSocketBuffer

    protected boolean useSocketBuffer

  Socket buffer (extra buffering to reduce number of packets sent).

Constructor Detail

### InternalOutputBuffer

    public InternalOutputBuffer(Response response)

  Default constructor.

### InternalOutputBuffer

    public InternalOutputBuffer(Response response,
                                int headerBufferSize)

  Alternate constructor.

Method Detail

### setOutputStream

    public void setOutputStream(java.io.OutputStream outputStream)

  Set the underlying socket output stream.

### getOutputStream

    public java.io.OutputStream getOutputStream()

  Get the underlying socket output stream.

### setSocketBuffer

    public void setSocketBuffer(int socketBufferSize)

  Set the socket buffer size.

### addFilter

    public void addFilter(OutputFilter filter)

  Add an output filter to the filter library.

### getFilters

    public OutputFilter[] getFilters()

  Get filters.

### clearFilters

    public void clearFilters()

  Clear filters.

### addActiveFilter

    public void addActiveFilter(OutputFilter filter)

  Add an output filter to the filter library.

### flush

    public void flush()
               throws java.io.IOException

  Flush the response.

  Throws:
    `java.io.IOException` - an undelying I/O error occured

### reset

    public void reset()

  Reset current response.

  Throws:
    `java.lang.IllegalStateException` - if the response has already been committed

### 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.

### endRequest

    public void endRequest()
                    throws java.io.IOException

  End request.

  Throws:
    `java.io.IOException` - an undelying I/O error occured

### sendAck

    public void sendAck()
                 throws java.io.IOException

  Send an acknoledgement.

  Throws:
    `java.io.IOException`

### sendStatus

    public void sendStatus()

  Send the response status line.

### sendHeader

    public void sendHeader(MessageBytes name,
                           MessageBytes value)

  Send a header.

  Parameters:
    `name` - Header name
    `value` - Header value

### sendHeader

    public void sendHeader(ByteChunk name,
                           ByteChunk value)

  Send a header.

  Parameters:
    `name` - Header name
    `value` - Header value

### sendHeader

    public void sendHeader(java.lang.String name,
                           java.lang.String value)

  Send a header.

  Parameters:
    `name` - Header name
    `value` - Header value

### endHeaders

    public void endHeaders()

  End the header block.

### doWrite

    public int doWrite(ByteChunk chunk,
                       Response res)
                throws java.io.IOException

  Write the contents of a byte chunk.

  Specified by:
    `doWrite` in interface `OutputBuffer`
  Parameters:
    `chunk` - byte chunk
  Returns:
    number of bytes written
  Throws:
    `java.io.IOException` - an undelying I/O error occured

### commit

    protected void commit()
                   throws java.io.IOException

  Commit the response.

  Throws:
    `java.io.IOException` - an undelying I/O error occured

### write

    protected void write(MessageBytes mb)

  This method will write the contents of the specyfied message bytes buffer to the output stream, without filtering. This method is meant to be used to write the response header.

  Parameters:
    `mb` - data to be written

### write

    protected void write(ByteChunk bc)

  This method will write the contents of the specyfied message bytes buffer to the output stream, without filtering. This method is meant to be used to write the response header.

  Parameters:
    `bc` - data to be written

### write

    protected void write(byte[] b)

  This method will write the contents of the specyfied 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

### write

    protected void write(java.lang.String s)

  This method will write the contents of the specyfied String to the output stream, without filtering. This method is meant to be used to write the response header.

  Parameters:
    `s` - data to be written

### write

    protected void write(int i)

  This method will print the specified integer to the output stream, without filtering. This method is meant to be used to write the response header.

  Parameters:
    `i` - data to be written

### realWriteBytes

    public void realWriteBytes(byte[] cbuf,
                               int off,
                               int len)
                        throws java.io.IOException

  Callback to write data from the buffer.

  Specified by:
    `realWriteBytes` in interface `ByteChunk.ByteOutputChannel`
  Throws:
    `java.io.IOException`

Copyright © 2000-2003 Apache Software Foundation. All Rights Reserved.