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 Summary
FieldsModifier and TypeFieldDescriptionfinal intState when reading byte data.final intState when reading character data.protected B2CConverterCurrent byte to char converter.static final intDefault buffer size in bytes.final intInitial state before any read operation.protected static final StringManagerThe string manager for this package.Fields inherited from interface ApplicationBufferHandler
EMPTY -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.InputBuffer(int size) Alternate constructor which allows specifying the initial buffer size. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of bytes or characters available in the buffer.voidEnsures a byte-to-char converter is available, initializing one if necessary.voidclose()voidexpand(int size) Expand the byte buffer to at least the given size.Obtain the ByteBuffer this channel is targeting.booleanChecks if all data has been read from the input buffer.booleanisReady()Checks if the input buffer is ready for reading.voidmark(int readAheadLimit) booleanintread()intread(byte[] b, int off, int len) Reads bytes into the specified array.intread(char[] cbuf) intread(char[] cbuf, int off, int len) intread(ByteBuffer to) Transfers bytes from the buffer to the specified ByteBuffer.intreadByte()Reads a single byte from the buffer.booleanready()intRead new bytes.intReads characters from the byte buffer using the current converter.voidrecycle()Recycle the output buffer.voidreset()voidsetByteBuffer(ByteBuffer buffer) Set the byte buffer.voidsetReadListener(ReadListener listener) Sets the read listener for async request processing.voidsetRequest(Request coyoteRequest) Associated Coyote request.longskip(long n) Methods inherited from class Reader
nullReader, of, read, readAllAsString, readAllLines, transferTo
-
Field Details
-
sm
The string manager for this package. -
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault buffer size in bytes.- See Also:
-
INITIAL_STATE
public final int INITIAL_STATEInitial state before any read operation.- See Also:
-
CHAR_STATE
public final int CHAR_STATEState when reading character data.- See Also:
-
BYTE_STATE
public final int BYTE_STATEState when reading byte data.- See Also:
-
conv
Current byte to char converter.
-
-
Constructor Details
-
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 Details
-
setRequest
Associated Coyote request.- Parameters:
coyoteRequest- Associated Coyote request
-
recycle
public void recycle()Recycle the output buffer. -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- 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
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:
trueif all data has been read
-
isReady
public boolean isReady()Checks if the input buffer is ready for reading.- Returns:
trueif the buffer is ready
-
realReadBytes
Description copied from interface:ByteChunk.ByteInputChannelRead new bytes.- Specified by:
realReadBytesin interfaceByteChunk.ByteInputChannel- Returns:
- The number of bytes read
- Throws:
IOException- If an I/O error occurs during reading
-
readByte
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
Reads bytes into the specified array.- Parameters:
b- the buffer into which the data is readoff- the start offset in the destination arraylen- 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
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
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
- Overrides:
readin classReader- Throws:
IOException
-
read
- Overrides:
readin classReader- Throws:
IOException
-
read
- Specified by:
readin classReader- Throws:
IOException
-
skip
- Overrides:
skipin classReader- Throws:
IOException
-
ready
- Overrides:
readyin classReader- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classReader
-
mark
- Overrides:
markin classReader- Throws:
IOException
-
reset
- Overrides:
resetin classReader- Throws:
IOException
-
checkConverter
Ensures a byte-to-char converter is available, initializing one if necessary.- Throws:
IOException- if an I/O error occurs
-
setByteBuffer
Description copied from interface:ApplicationBufferHandlerSet the byte buffer.- Specified by:
setByteBufferin interfaceApplicationBufferHandler- Parameters:
buffer- the byte buffer
-
getByteBuffer
Description copied from interface:ByteChunk.ByteInputChannelObtain the ByteBuffer this channel is targeting.- Specified by:
getByteBufferin interfaceApplicationBufferHandler- Specified by:
getByteBufferin interfaceByteChunk.ByteInputChannel- Returns:
- the ByteBuffer this channel is targeting
-
expand
public void expand(int size) Description copied from interface:ApplicationBufferHandlerExpand the byte buffer to at least the given size. Some implementations may not implement this.- Specified by:
expandin interfaceApplicationBufferHandler- Parameters:
size- the desired size
-