Top Description Inners Fields Constructors Methods
org.apache.catalina.connector

public Class InputBuffer

extends Reader
implements ByteInputChannel, ApplicationBufferHandler
Class Inheritance
All Implemented Interfaces
org.apache.tomcat.util.net.ApplicationBufferHandler, org.apache.tomcat.util.buf.ByteChunk.ByteInputChannel
Imports
java.io.IOException, .Reader, java.net.SocketTimeoutException, java.nio.Buffer, .ByteBuffer, .CharBuffer, java.nio.charset.Charset, java.security.AccessController, .PrivilegedActionException, .PrivilegedExceptionAction, java.util.Map, java.util.concurrent.ConcurrentHashMap, jakarta.servlet.ReadListener, .RequestDispatcher, jakarta.servlet.http.HttpServletResponse, org.apache.catalina.security.SecurityUtil, org.apache.coyote.ActionCode, .BadRequestException, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.buf.B2CConverter, .ByteChunk, org.apache.tomcat.util.collections.SynchronizedStack, org.apache.tomcat.util.net.ApplicationBufferHandler, org.apache.tomcat.util.res.StringManager

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private ByteBuffer
bb

The byte buffer.

public final int
private CharBuffer
cb

The char buffer.

public final int
private boolean
closed

Flag which indicates if the input buffer is closed.

protected B2CConverter
conv

Current byte to char converter.

private Request
coyoteRequest

Associated Coyote request.

public static final int
private static final Map<Charset, SynchronizedStack<B2CConverter>>
encoders

Encoder cache.

public final int
private static final Log
private int
markPos

Buffer position.

private int
readLimit

Char buffer limit.

private final int
size

Buffer size.

protected static final StringManager
sm

The string manager for this package.

private int
state

State of the output buffer.

Inherited from java.io.Reader:
lock

Constructor Summary

AccessConstructor and Description
public
InputBuffer()

Default constructor.

public
InputBuffer(int
Buffer size to use
size
)

Alternate constructor which allows specifying the initial buffer size.

Method Summary

Modifier and TypeMethod and Description
public int
private int
private boolean
private boolean
public void
private void
clear(Buffer buffer)

public void
close()

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Close the input buffer.

private static B2CConverter
public void
public ByteBuffer
private void
pack-priv boolean
public boolean
public boolean
private void
makeSpace(int count)

public void
mark(int
Limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream may fail.
readAheadLimit
)

Overrides java.io.Reader.mark.

Marks the present position in the stream.

public boolean
markSupported()

Overrides java.io.Reader.markSupported.

Tells whether this stream supports the mark() operation.

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

public int

Returns:

an integer specifying the actual number of bytes read, or -1 if the end of the stream is reached
read
(ByteBuffer
the ByteBuffer into which bytes are to be written.
to
)

Transfers bytes from the buffer to the specified ByteBuffer.

public int
read()

Overrides java.io.Reader.read.

Reads a single character.

public int
read(char[]
Destination buffer
cbuf
)

Overrides java.io.Reader.read.

Reads characters into an array.

public int
read(char[]
Destination buffer
cbuf
,
int
Offset at which to start storing characters
off
,
int
Maximum number of characters to read
len
)

Implements abstract java.io.Reader.read.

Reads characters into a portion of an array.

public int
public boolean
ready()

Overrides java.io.Reader.ready.

Tells whether this stream is ready to be read.

public int
public int
public void
recycle()

Recycle the output buffer.

public void
reset()

Overrides java.io.Reader.reset.

Resets the stream.

public void
public void
public void
setRequest(Request
Associated Coyote request
coyoteRequest
)

Associated Coyote request.

public long
skip(long
The number of characters to skip
n
)

Overrides java.io.Reader.skip.

Skips characters.

private void
Inherited from java.io.Reader:
nullReaderreadtransferTo

Field Detail

bbback to summary
private ByteBuffer bb

The byte buffer.

BYTE_STATEback to summary
public final int BYTE_STATE
cbback to summary
private CharBuffer cb

The char buffer.

CHAR_STATEback to summary
public final int CHAR_STATE
closedback to summary
private boolean closed

Flag which indicates if the input buffer is closed.

convback to summary
protected B2CConverter conv

Current byte to char converter.

coyoteRequestback to summary
private Request coyoteRequest

Associated Coyote request.

DEFAULT_BUFFER_SIZEback to summary
public static final int DEFAULT_BUFFER_SIZE
encodersback to summary
private static final Map<Charset, SynchronizedStack<B2CConverter>> encoders

Encoder cache.

INITIAL_STATEback to summary
public final int INITIAL_STATE
logback to summary
private static final Log log
markPosback to summary
private int markPos

Buffer position.

readLimitback to summary
private int readLimit

Char buffer limit.

sizeback to summary
private final int size

Buffer size.

smback to summary
protected static final StringManager sm

The string manager for this package.

stateback to summary
private int state

State of the output buffer.

Constructor Detail

InputBufferback to summary
public InputBuffer()

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

InputBufferback to summary
public InputBuffer(int size)

Alternate constructor which allows specifying the initial buffer size.

Parameters
size:int

Buffer size to use

Method Detail

availableback to summary
public int available()
availableInThisBufferback to summary
private int availableInThisBuffer()
checkByteBufferEofback to summary
private boolean checkByteBufferEof() throws IOException
checkCharBufferEofback to summary
private boolean checkCharBufferEof() throws IOException
checkConverterback to summary
public void checkConverter() throws IOException
clearback to summary
private void clear(Buffer buffer)
closeback to summary
public void close() throws IOException

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Close the input buffer.

Annotations
@Override
Exceptions
IOException:
An underlying IOException occurred
createConverterback to summary
private static B2CConverter createConverter(Charset charset) throws IOException
expandback to summary
public void expand(int size)

Implements org.apache.tomcat.util.net.ApplicationBufferHandler.expand.

Annotations
@Override
getByteBufferback to summary
public ByteBuffer getByteBuffer()

Implements org.apache.tomcat.util.net.ApplicationBufferHandler.getByteBuffer.

Annotations
@Override
handleReadExceptionback to summary
private void handleReadException(Exception e) throws IOException
isBlockingback to summary
pack-priv boolean isBlocking()
isFinishedback to summary
public boolean isFinished()
isReadyback to summary
public boolean isReady()
makeSpaceback to summary
private void makeSpace(int count)
markback to summary
public void mark(int readAheadLimit) throws IOException

Overrides java.io.Reader.mark.

Doc from java.io.Reader.mark.

Marks the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point. Not all character-input streams support the mark() operation.

Parameters
readAheadLimit:int

Limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream may fail.

Annotations
@Override
Exceptions
IOException:
If the stream does not support mark(), or if some other I/O error occurs
markSupportedback to summary
public boolean markSupported()

Overrides java.io.Reader.markSupported.

Doc from java.io.Reader.markSupported.

Tells whether this stream supports the mark() operation. The default implementation always returns false. Subclasses should override this method.

Returns:boolean

true if and only if this stream supports the mark operation.

Annotations
@Override
readback to summary
public int read(byte[] b, int off, int len) throws IOException
readback to summary
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:ByteBuffer

the ByteBuffer into which bytes are to be written.

Returns:int

an integer specifying the actual number of bytes read, or -1 if the end of the stream is reached

Exceptions
IOException:
if an input or output exception has occurred
readback to summary
public int read() throws IOException

Overrides java.io.Reader.read.

Doc from java.io.Reader.read.

Reads a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.

Subclasses that intend to support efficient single-character input should override this method.

Returns:int

The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readback to summary
public int read(char[] cbuf) throws IOException

Overrides java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If the length of cbuf is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Parameters
cbuf:char[]

Destination buffer

Returns:int

The number of characters read, or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readback to summary
public int read(char[] cbuf, int off, int len) throws IOException

Implements abstract java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If len is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Parameters
cbuf:char[]

Destination buffer

off:int

Offset at which to start storing characters

len:int

Maximum number of characters to read

Returns:int

The number of characters read, or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readByteback to summary
public int readByte() throws IOException
readyback to summary
public boolean ready() throws IOException

Overrides java.io.Reader.ready.

Doc from java.io.Reader.ready.

Tells whether this stream is ready to be read.

Returns:boolean

True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
realReadBytesback to summary
public int realReadBytes() throws IOException

Implements org.apache.tomcat.util.buf.ByteChunk.ByteInputChannel.realReadBytes.

Reads new bytes in the byte chunk.

Returns:int

Doc from org.apache.tomcat.util.buf.ByteChunk.ByteInputChannel.realReadBytes.

The number of bytes read

Annotations
@Override
Exceptions
IOException:
An underlying IOException occurred
realReadCharsback to summary
public int realReadChars() throws IOException
recycleback to summary
public void recycle()

Recycle the output buffer.

resetback to summary
public void reset() throws IOException

Overrides java.io.Reader.reset.

Doc from java.io.Reader.reset.

Resets the stream. If the stream has been marked, then attempt to reposition it at the mark. If the stream has not been marked, then attempt to reset it in some way appropriate to the particular stream, for example by repositioning it to its starting point. Not all character-input streams support the reset() operation, and some support reset() without supporting mark().

Annotations
@Override
Exceptions
IOException:
If the stream has not been marked, or if the mark has been invalidated, or if the stream does not support reset(), or if some other I/O error occurs
setByteBufferback to summary
public void setByteBuffer(ByteBuffer buffer)

Implements org.apache.tomcat.util.net.ApplicationBufferHandler.setByteBuffer.

Annotations
@Override
setReadListenerback to summary
public void setReadListener(ReadListener listener)
setRequestback to summary
public void setRequest(Request coyoteRequest)

Associated Coyote request.

Parameters
coyoteRequest:Request

Associated Coyote request

skipback to summary
public long skip(long n) throws IOException

Overrides java.io.Reader.skip.

Doc from java.io.Reader.skip.

Skips characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached. If the stream is already at its end before this method is invoked, then no characters are skipped and zero is returned.

Parameters
n:long

The number of characters to skip

Returns:long

The number of characters actually skipped

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
throwIfClosedback to summary
private void throwIfClosed() throws IOException
org.apache.catalina.connector back to summary

private Class InputBuffer.PrivilegedCreateConverter

extends Object
implements PrivilegedExceptionAction<B2CConverter>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.connector.InputBuffer.PrivilegedCreateConverter
All Implemented Interfaces
java.security.PrivilegedExceptionAction

Field Summary

Modifier and TypeField and Description
private final Charset

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public B2CConverter
run()

Implements java.security.PrivilegedExceptionAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charsetback to summary
private final Charset charset

Constructor Detail

PrivilegedCreateConverterback to summary
pack-priv PrivilegedCreateConverter(Charset charset)

Method Detail

runback to summary
public B2CConverter run() throws IOException

Implements java.security.PrivilegedExceptionAction.run.

Doc from java.security.PrivilegedExceptionAction.run.

Performs the computation. This method will be called by AccessController.doPrivileged after enabling privileges.

Returns:B2CConverter

a class-dependent value that may represent the results of the computation. Each class that implements PrivilegedExceptionAction should document what (if anything) this value represents.

Annotations
@Override