OutputBuffer (Apache Tomcat 7.0.104 API Documentation)

org.apache.catalina.connector

## Class OutputBuffer

- java.lang.Object
- - java.io.Writer
  - - org.apache.catalina.connector.OutputBuffer

- All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable, ByteChunk.ByteOutputChannel, CharChunk.CharOutputChannel

      public class OutputBuffer
      extends Writer
      implements ByteChunk.ByteOutputChannel, CharChunk.CharOutputChannel

  The buffer used by Tomcat response. This is a derivative of the Tomcat 3.3 OutputBuffer, with the removal of some of the state handling (which in Coyote is mostly the Processor's responsibility).
  Author:
    Costin Manolache, Remy Maucherat

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected C2BConverter` | `conv` Current char to byte converter.
    `static int` | `DEFAULT_BUFFER_SIZE`
    `static String` | `DEFAULT_ENCODING`
    `protected ConcurrentHashMap<String,C2BConverter>` | `encoders` List of encoders.

    - ### Fields inherited from class java.io.Writer

      `lock`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `OutputBuffer()` Default constructor.
    `OutputBuffer(int size)` Alternate constructor which allows specifying the initial buffer size.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `checkConverter()`
    `void` | `clearEncoders()` Clear cached encoders (to save memory for Comet requests).
    `void` | `close()` Close the output buffer.
    `protected void` | `doFlush(boolean realFlush)` Flush bytes or chars contained in the buffer.
    `void` | `flush()` Flush bytes or chars contained in the buffer.
    `int` | `getBufferSize()`
    `long` | `getContentWritten()`
    `Response` | `getResponse()` Deprecated.
    `boolean` | `isClosed()` Is the response output closed ?
    `boolean` | `isNew()` Has this buffer been used at all?
    `boolean` | `isSuspended()` Is the response output suspended ?
    `void` | `realWriteBytes(byte[] buf, int off, int cnt)` Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.
    `void` | `realWriteChars(char[] buf, int off, int len)` Convert the chars to bytes, then send the data to the client.
    `void` | `recycle()` Recycle the output buffer.
    `void` | `reset()`
    `void` | `reset(boolean resetWriterStreamFlags)`
    `void` | `setBufferSize(int size)`
    `protected void` | `setConverter()`
    `void` | `setEncoding(String s)`
    `void` | `setResponse(Response coyoteResponse)` Associated Coyote response.
    `void` | `setSuspended(boolean suspended)` Set the suspended flag.
    `void` | `write(byte[] b, int off, int len)`
    `void` | `write(char[] c)`
    `void` | `write(char[] c, int off, int len)`
    `void` | `write(int c)`
    `void` | `write(String s)`
    `void` | `write(String s, int off, int len)` Append a string to the buffer
    `void` | `writeByte(int b)`

    - ### Methods inherited from class java.io.Writer

      `append, append, append`

    - ### Methods inherited from class java.lang.Object

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

- - ### Field Detail

    - #### DEFAULT_ENCODING

          public static final String DEFAULT_ENCODING

      See Also:
        Constant Field Values

    - #### DEFAULT_BUFFER_SIZE

          public static final int DEFAULT_BUFFER_SIZE

      See Also:
        Constant Field Values

    - #### encoders

          protected final ConcurrentHashMap<String,C2BConverter> encoders

      List of encoders.

    - #### conv

          protected C2BConverter conv

      Current char to byte converter.

  - ### Constructor Detail

    - #### OutputBuffer

          public OutputBuffer()

      Default constructor. Allocate the buffer with the default buffer size.

    - #### OutputBuffer

          public OutputBuffer(int size)

      Alternate constructor which allows specifying the initial buffer size.
      Parameters:
        `size` - Buffer size to use

  - ### Method Detail

    - #### setResponse

          public void setResponse(Response coyoteResponse)

      Associated Coyote response.
      Parameters:
        `coyoteResponse` - Associated Coyote response

    - #### getResponse

          @Deprecated
          public Response getResponse()

      Deprecated.
      Get associated Coyote response.
      Returns:
        the associated Coyote response

    - #### isSuspended

          public boolean isSuspended()

      Is the response output suspended ?
      Returns:
        suspended flag value

    - #### setSuspended

          public void setSuspended(boolean suspended)

      Set the suspended flag.
      Parameters:
        `suspended` - New suspended flag value

    - #### isClosed

          public boolean isClosed()

      Is the response output closed ?
      Returns:
        closed flag value

    - #### recycle

          public void recycle()

      Recycle the output buffer.

    - #### clearEncoders

          public void clearEncoders()

      Clear cached encoders (to save memory for Comet requests).

    - #### close

          public void close()
                     throws IOException

      Close the output buffer. This tries to calculate the response size if the response has not been committed yet.
      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in class `Writer`
      Throws:
        `IOException` - An underlying IOException occurred

    - #### flush

          public void flush()
                     throws IOException

      Flush bytes or chars contained in the buffer.
      Specified by:
        `flush` in interface `Flushable`
      Specified by:
        `flush` in class `Writer`
      Throws:
        `IOException` - An underlying IOException occurred

    - #### doFlush

          protected void doFlush(boolean realFlush)
                          throws IOException

      Flush bytes or chars contained in the buffer.
      Parameters:
        `realFlush` - `true` if this should also cause a real network flush
      Throws:
        `IOException` - An underlying IOException occurred

    - #### realWriteBytes

          public void realWriteBytes(byte[] buf,
                            int off,
                            int cnt)
                              throws IOException

      Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.
      Specified by:
        `realWriteBytes` in interface `ByteChunk.ByteOutputChannel`
      Parameters:
        `buf` - Byte buffer to be written to the response
        `off` - Offset
        `cnt` - Length
      Throws:
        `IOException` - An underlying IOException occurred

    - #### write

          public void write(byte[] b,
                   int off,
                   int len)
                     throws IOException

      Throws:
        `IOException`

    - #### writeByte

          public void writeByte(int b)
                         throws IOException

      Throws:
        `IOException`

    - #### realWriteChars

          public void realWriteChars(char[] buf,
                            int off,
                            int len)
                              throws IOException

      Convert the chars to bytes, then send the data to the client.
      Specified by:
        `realWriteChars` in interface `CharChunk.CharOutputChannel`
      Parameters:
        `buf` - Char buffer to be written to the response
        `off` - Offset
        `len` - Length
      Throws:
        `IOException` - An underlying IOException occurred

    - #### write

          public void write(int c)
                     throws IOException

      Overrides:
        `write` in class `Writer`
      Throws:
        `IOException`

    - #### write

          public void write(char[] c)
                     throws IOException

      Overrides:
        `write` in class `Writer`
      Throws:
        `IOException`

    - #### write

          public void write(char[] c,
                   int off,
                   int len)
                     throws IOException

      Specified by:
        `write` in class `Writer`
      Throws:
        `IOException`

    - #### write

          public void write(String s,
                   int off,
                   int len)
                     throws IOException

      Append a string to the buffer
      Overrides:
        `write` in class `Writer`
      Throws:
        `IOException`

    - #### write

          public void write(String s)
                     throws IOException

      Overrides:
        `write` in class `Writer`
      Throws:
        `IOException`

    - #### setEncoding

          public void setEncoding(String s)

    - #### checkConverter

          public void checkConverter()
                              throws IOException

      Throws:
        `IOException`

    - #### setConverter

          protected void setConverter()
                               throws IOException

      Throws:
        `IOException`

    - #### getContentWritten

          public long getContentWritten()

    - #### isNew

          public boolean isNew()

      Has this buffer been used at all?
      Returns:
        true if no chars or bytes have been added to the buffer since the last call to `recycle()`

    - #### setBufferSize

          public void setBufferSize(int size)

    - #### reset

          public void reset()

    - #### reset

          public void reset(boolean resetWriterStreamFlags)

    - #### getBufferSize

          public int getBufferSize()

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