CoyoteInputStream (Apache Tomcat 11.0.21 API Documentation)
Description: declaration: package: org.apache.catalina.connector, class: CoyoteInputStream

# Class CoyoteInputStream

java.lang.Object
java.io.InputStream
jakarta.servlet.ServletInputStream
org.apache.catalina.connector.CoyoteInputStream

All Implemented Interfaces:
  `Closeable, AutoCloseable`

public class CoyoteInputStream extends ServletInputStream
This class handles reading bytes.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected InputBuffer`
  `ib`
  `protected static final StringManager`
  `sm`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `CoyoteInputStream(InputBuffer ib)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `available()`
  `protected Object`
  `clone()`
  Prevent cloning the facade.
  `void`
  `close()`
  Close the stream Since we re-cycle, we can't allow the call to super.close() which would permanently disable us.
  `boolean`
  `isFinished()`
  Has the end of this InputStream been reached?
  `boolean`
  `isReady()`
  Returns `true` if it is allowable to call a `read()` method.
  `int`
  `read()`
  `int`
  `read(byte[] b)`
  `int`
  `read(byte[] b, int off, int len)`
  `int`
  `read(ByteBuffer b)`
  Reads from the input stream into the given buffer.
  `void`
  `setReadListener(ReadListener listener)`
  Sets the `ReadListener` for this `ServletInputStream` and thereby switches to non-blocking IO.

  ### Methods inherited from class ServletInputStream

  `readAllBytes, readLine, readNBytes, readNBytes`

  ### Methods inherited from class InputStream

  `mark, markSupported, nullInputStream, reset, skip, skipNBytes, transferTo`

  ### Methods inherited from class Object

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

- ## Field Details

  - ### sm

    protected static final StringManager sm

  - ### ib

    protected InputBuffer ib

- ## Constructor Details

  - ### CoyoteInputStream

    protected CoyoteInputStream(InputBuffer ib)

- ## Method Details

  - ### clone

    protected Object clone() throws CloneNotSupportedException
    Prevent cloning the facade.
    Overrides:
      `clone` in class `Object`
    Throws:
      `CloneNotSupportedException`

  - ### read

    public int read() throws IOException
    Specified by:
      `read` in class `InputStream`
    Throws:
      `IOException`

  - ### available

    public int available() throws IOException
    Overrides:
      `available` in class `InputStream`
    Throws:
      `IOException`

  - ### read

    public int read(byte[] b) throws IOException
    Overrides:
      `read` in class `InputStream`
    Throws:
      `IOException`

  - ### read

    public int read(byte[] b, int off, int len) throws IOException
    Overrides:
      `read` in class `InputStream`
    Throws:
      `IOException`

  - ### read

    public int read(ByteBuffer b) throws IOException
    Description copied from class: `jakarta.servlet.ServletInputStream`
    Reads from the input stream into the given buffer.

    If the input stream is in non-blocking mode, before each invocation of this method `ServletInputStream.isReady()` must be called and must return `true` or the `ReadListener.onDataAvailable()` call back must indicate that data is available to read else an `IllegalStateException` must be thrown.

    Otherwise, if this method is called when `buffer` has no space remaining, the method returns `0` immediately and `buffer` is unchanged.

    If the input stream is in blocking mode and `buffer` has space remaining, this method blocks until at least one byte has been read, end of stream is reached or an exception is thrown.

    Returns the number of bytes read or `-1` if the end of stream is reached without reading any data.

    When the method returns, and if data has been read, the buffer's position will be unchanged from the value when passed to this method and the limit will be the position incremented by the number of bytes read.

    Subclasses are strongly encouraged to override this method and provide a more efficient implementation.

    Overrides:
      `read` in class `ServletInputStream`
    Parameters:
      `b` - The buffer into which the data is read.
    Returns:
      The number of bytes read or `-1` if the end of the stream has been reached.
    Throws:
      `IOException` - If data cannot be read for any reason other than the end of stream being reached, the input stream has been closed or if some other I/O error occurs.

  - ### close

    public void close() throws IOException
    Close the stream Since we re-cycle, we can't allow the call to super.close() which would permanently disable us.
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Overrides:
      `close` in class `InputStream`
    Throws:
      `IOException`

  - ### isFinished

    public boolean isFinished()
    Description copied from class: `jakarta.servlet.ServletInputStream`
    Has the end of this InputStream been reached?
    Specified by:
      `isFinished` in class `ServletInputStream`
    Returns:
      `true` if all the data has been read from the stream, else `false`

  - ### isReady

    public boolean isReady()
    Description copied from class: `jakarta.servlet.ServletInputStream`
    Returns `true` if it is allowable to call a `read()` method. In blocking mode, this method will always return `true`, but a subsequent call to a `read()` method may block awaiting data. In non-blocking mode this method may return `false`, in which case it is illegal to call a `read()` method and an `IllegalStateException` MUST be thrown. When `ReadListener.onDataAvailable()` is called, a call to this method that returned `true` is implicit.

    If this method returns `false` and a `ReadListener` has been set via `ServletInputStream.setReadListener(ReadListener)`, then the container will subsequently invoke `ReadListener.onDataAvailable()` (or `ReadListener.onAllDataRead()`) once data (or EOF) has become available. Other than the initial call `ReadListener.onDataAvailable()` will only be called if and only if this method is called and returns false.

    Specified by:
      `isReady` in class `ServletInputStream`
    Returns:
      `true` if data can be obtained without blocking, otherwise returns `false`.

  - ### setReadListener

    public void setReadListener(ReadListener listener)
    Description copied from class: `jakarta.servlet.ServletInputStream`
    Sets the `ReadListener` for this `ServletInputStream` and thereby switches to non-blocking IO. It is only valid to switch to non-blocking IO within async processing or HTTP upgrade processing.
    Specified by:
      `setReadListener` in class `ServletInputStream`
    Parameters:
      `listener` - The non-blocking IO read listener