org.apache.catalina.connector

## Class InputBuffer

- java.lang.Object
- - java.io.Reader
  - - org.apache.catalina.connector.InputBuffer

All Implemented Interfaces:
  Closeable, AutoCloseable, Readable, ByteChunk.ByteInputChannel, CharChunk.CharInputChannel, CharChunk.CharOutputChannel

    public class InputBuffer
    extends Reader
    implements ByteChunk.ByteInputChannel, CharChunk.CharInputChannel, CharChunk.CharOutputChannel

The buffer used by Tomcat request. This is a derivative of the Tomcat 3.3 OutputBuffer, adapted to handle input instead of output. This allows complete recycling of the facade objects (the ServletInputStream and the BufferedReader).

Author:
  Remy Maucherat

### Field Summary

Fields
`int` `BYTE_STATE`
`int` `CHAR_STATE`
`protected B2CConverter` `conv` Current byte to char converter.
`static int` `DEFAULT_BUFFER_SIZE`
`static String` `DEFAULT_ENCODING`
`protected HashMap<String,B2CConverter>` `encoders` List of encoders.
`int` `INITIAL_STATE`
`protected static StringManager` `sm` The string manager for this package.

### Fields inherited from class java.io.Reader

`lock`

### Constructor Summary

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

### Method Summary

Methods
`int` `available()`
`void` `checkConverter()`
`void` `clearEncoders()` Clear cached encoders (to save memory for Comet requests).
`void` `close()` Close the input buffer.
`Request` `getRequest()` Deprecated.
`void` `mark(int readAheadLimit)`
`boolean` `markSupported()`
`int` `read()`
`int` `read(byte[] b, int off, int len)`
`int` `read(char[] cbuf)`
`int` `read(char[] cbuf, int off, int len)`
`int` `readByte()`
`boolean` `ready()`
`int` `realReadBytes(byte[] cbuf, int off, int len)` Reads new bytes in the byte chunk.
`int` `realReadChars(char[] cbuf, int off, int len)` Read new bytes ( usually the internal conversion buffer ).
`void` `realWriteChars(char[] c, int off, int len)` Since the converter will use append, it is possible to get chars to be removed from the buffer for "writing".
`void` `recycle()` Recycle the output buffer.
`void` `reset()`
`protected void` `setConverter()`
`void` `setEncoding(String s)`
`void` `setRequest(Request coyoteRequest)` Associated Coyote request.
`long` `skip(long n)`

### Methods inherited from class java.io.Reader

`read`

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

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

### Field Detail

#### sm

    protected static final StringManager sm

The string manager for this package.

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

#### INITIAL_STATE

    public final int INITIAL_STATE

See Also:
  Constant Field Values

#### CHAR_STATE

    public final int CHAR_STATE

See Also:
  Constant Field Values

#### BYTE_STATE

    public final int BYTE_STATE

See Also:
  Constant Field Values

#### encoders

    protected HashMap<String,B2CConverter> encoders

List of encoders.

#### conv

    protected B2CConverter conv

Current byte to char converter.

### Constructor Detail

#### InputBuffer

    public InputBuffer()

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

#### InputBuffer

    public InputBuffer(int size)

Alternate constructor which allows specifying the initial buffer size.

Parameters:
  `size` - Buffer size to use

### Method Detail

#### setRequest

    public void setRequest(Request coyoteRequest)

Associated Coyote request.

Parameters:
  `coyoteRequest` - Associated Coyote request

#### getRequest

    @Deprecated
    public Request getRequest()

Deprecated.
Get associated Coyote request.

Returns:
  the associated Coyote request

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

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in class `Reader`
Throws:
  `IOException` - An underlying IOException occurred

#### available

    public int available()

#### realReadBytes

    public int realReadBytes(byte[] cbuf,
                    int off,
                    int len)
                      throws IOException

Reads new bytes in the byte chunk.

Specified by:
  `realReadBytes` in interface `ByteChunk.ByteInputChannel`
Parameters:
  `cbuf` - Byte buffer to be written to the response
  `off` - Offset
  `len` - Length
Throws:
  `IOException` - An underlying IOException occurred

#### readByte

    public int readByte()
                 throws IOException

Throws:
  `IOException`

#### read

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

Throws:
  `IOException`

#### realWriteChars

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

Since the converter will use append, it is possible to get chars to be removed from the buffer for "writing". Since the chars have already been read before, they are ignored. If a mark was set, then the mark is lost.

Specified by:
  `realWriteChars` in interface `CharChunk.CharOutputChannel`
Throws:
  `IOException`

#### setEncoding

    public void setEncoding(String s)

#### realReadChars

    public int realReadChars(char[] cbuf,
                    int off,
                    int len)
                      throws IOException

Description copied from interface: `CharChunk.CharInputChannel`
Read new bytes ( usually the internal conversion buffer ). The implementation is allowed to ignore the parameters, and mutate the chunk if it wishes to implement its own buffering.

Specified by:
  `realReadChars` in interface `CharChunk.CharInputChannel`
Throws:
  `IOException`

#### read

    public int read()
             throws IOException

Overrides:
  `read` in class `Reader`
Throws:
  `IOException`

#### read

    public int read(char[] cbuf)
             throws IOException

Overrides:
  `read` in class `Reader`
Throws:
  `IOException`

#### read

    public int read(char[] cbuf,
           int off,
           int len)
             throws IOException

Specified by:
  `read` in class `Reader`
Throws:
  `IOException`

#### skip

    public long skip(long n)
              throws IOException

Overrides:
  `skip` in class `Reader`
Throws:
  `IOException`

#### ready

    public boolean ready()
                  throws IOException

Overrides:
  `ready` in class `Reader`
Throws:
  `IOException`

#### markSupported

    public boolean markSupported()

Overrides:
  `markSupported` in class `Reader`

#### mark

    public void mark(int readAheadLimit)
              throws IOException

Overrides:
  `mark` in class `Reader`
Throws:
  `IOException`

#### reset

    public void reset()
               throws IOException

Overrides:
  `reset` in class `Reader`
Throws:
  `IOException`

#### checkConverter

    public void checkConverter()
                        throws IOException

Throws:
  `IOException`

#### setConverter

    protected void setConverter()
                         throws IOException

Throws:
  `IOException`