Class InputBuffer

java.lang.Object
java.io.Reader
org.apache.catalina.connector.InputBuffer
All Implemented Interfaces:
Closeable, AutoCloseable, Readable, ByteChunk.ByteInputChannel, ApplicationBufferHandler

public class InputBuffer extends Reader implements ByteChunk.ByteInputChannel, ApplicationBufferHandler
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).
  • Field Details

    • sm

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

      public static final int DEFAULT_BUFFER_SIZE
      Default buffer size in bytes.
      See Also:
    • INITIAL_STATE

      public final int INITIAL_STATE
      Initial state before any read operation.
      See Also:
    • CHAR_STATE

      public final int CHAR_STATE
      State when reading character data.
      See Also:
    • BYTE_STATE

      public final int BYTE_STATE
      State when reading byte data.
      See Also:
    • conv

      protected B2CConverter conv
      Current byte to char converter.
  • Constructor Details

    • InputBuffer

      public InputBuffer(Request coyoteRequest)
      Default constructor. Allocate the buffer with the default buffer size.
      Parameters:
      coyoteRequest - The associated Coyote request
    • InputBuffer

      public InputBuffer(int size, Request coyoteRequest)
      Alternate constructor which allows specifying the initial buffer size.
      Parameters:
      size - Buffer size to use
      coyoteRequest - The associated Coyote request
  • Method Details

    • recycle

      public void recycle()
      Recycle the output buffer.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Reader
      Throws:
      IOException
    • available

      public int available()
      Returns the number of bytes or characters available in the buffer.
      Returns:
      the number of bytes or characters available
    • setReadListener

      public void setReadListener(ReadListener listener)
      Sets the read listener for async request processing.
      Parameters:
      listener - the read listener to set
    • isFinished

      public boolean isFinished()
      Checks if all data has been read from the input buffer.
      Returns:
      true if all data has been read
    • isReady

      public boolean isReady()
      Checks if the input buffer is ready for reading.
      Returns:
      true if the buffer is ready
    • realReadBytes

      public int realReadBytes() throws IOException
      Description copied from interface: ByteChunk.ByteInputChannel
      Read new bytes.
      Specified by:
      realReadBytes in interface ByteChunk.ByteInputChannel
      Returns:
      The number of bytes read
      Throws:
      IOException - If an I/O error occurs during reading
    • readByte

      public int readByte() throws IOException
      Reads a single byte from the buffer.
      Returns:
      the byte read, or -1 if end of stream
      Throws:
      IOException - if an I/O error occurs
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Reads bytes into the specified array.
      Parameters:
      b - the buffer into which the data is read
      off - the start offset in the destination array
      len - the maximum number of bytes to read
      Returns:
      the number of bytes read, or -1 if end of stream
      Throws:
      IOException - if an I/O error occurs
    • read

      public int read(ByteBuffer to) throws IOException
      Transfers bytes from the buffer to the specified ByteBuffer. After the operation the position of the ByteBuffer will be returned to the one before the operation, the limit will be the position incremented by the number of the transferred bytes.
      Parameters:
      to - the ByteBuffer into which bytes are to be written.
      Returns:
      an integer specifying the actual number of bytes read, or -1 if the end of the stream is reached
      Throws:
      IOException - if an input or output exception has occurred
    • realReadChars

      public int realReadChars() throws IOException
      Reads characters from the byte buffer using the current converter.
      Returns:
      the number of characters read, or -1 if end of stream
      Throws:
      IOException - if an I/O error occurs
    • 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
      Ensures a byte-to-char converter is available, initializing one if necessary.
      Throws:
      IOException - if an I/O error occurs
    • setByteBuffer

      public void setByteBuffer(ByteBuffer buffer)
      Description copied from interface: ApplicationBufferHandler
      Set the byte buffer.
      Specified by:
      setByteBuffer in interface ApplicationBufferHandler
      Parameters:
      buffer - the byte buffer
    • getByteBuffer

      public ByteBuffer getByteBuffer()
      Description copied from interface: ByteChunk.ByteInputChannel
      Obtain the ByteBuffer this channel is targeting.
      Specified by:
      getByteBuffer in interface ApplicationBufferHandler
      Specified by:
      getByteBuffer in interface ByteChunk.ByteInputChannel
      Returns:
      the ByteBuffer this channel is targeting
    • expand

      public void expand(int size)
      Description copied from interface: ApplicationBufferHandler
      Expand the byte buffer to at least the given size. Some implementations may not implement this.
      Specified by:
      expand in interface ApplicationBufferHandler
      Parameters:
      size - the desired size