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

public Class CoyoteInputStream

extends ServletInputStream
Class Inheritance
Imports
java.io.IOException, java.nio.ByteBuffer, java.security.AccessController, .PrivilegedActionException, .PrivilegedExceptionAction, java.util.Objects, jakarta.servlet.ReadListener, .ServletInputStream, org.apache.catalina.security.SecurityUtil, org.apache.tomcat.util.res.StringManager

This class handles reading bytes.
Author
Remy Maucherat

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
protected InputBuffer
protected static final StringManager

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public int
available()

Overrides java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.

private void
pack-priv void
clear()

Clear facade.

protected Object
clone()

Overrides java.lang.Object.clone.

Prevent cloning the facade.

public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Close the stream Since we re-cycle, we can't allow the call to super.close() which would permanently disable us.

public boolean
isFinished()

Implements abstract jakarta.servlet.ServletInputStream.isFinished.

Has the end of this InputStream been reached?

public boolean
isReady()

Implements abstract jakarta.servlet.ServletInputStream.isReady.

Can data be read from this InputStream without blocking?

public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int
read(final byte[]
the buffer into which the data is read.
b
)

Overrides java.io.InputStream.read.

Reads some number of bytes from the input stream and stores them into the buffer array b.

public int
read(final byte[]
the buffer into which the data is read.
b
,
final int
the start offset in array b at which the data is written.
off
,
final int
the maximum number of bytes to read.
len
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

public int

Returns:

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

Transfers bytes from the buffer to the specified ByteBuffer.

public void
setReadListener(ReadListener
The non-blocking IO read listener
listener
)

Implements abstract jakarta.servlet.ServletInputStream.setReadListener.

Sets the ReadListener for this ServletInputStream and thereby switches to non-blocking IO.

Inherited from jakarta.servlet.ServletInputStream:
readLine

Field Detail

ibback to summary
protected InputBuffer ib
smback to summary
protected static final StringManager sm

Constructor Detail

CoyoteInputStreamback to summary
protected CoyoteInputStream(InputBuffer ib)

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.InputStream.available.

Doc from java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

A subclass's implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method.

Returns:int

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
checkNonBlockingReadback to summary
private void checkNonBlockingRead()
clearback to summary
pack-priv void clear()

Clear facade.

cloneback to summary
protected Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Prevent cloning the facade.

Returns:Object

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
Exceptions
CloneNotSupportedException:

Doc from java.lang.Object.clone.

if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.

closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Close the stream Since we re-cycle, we can't allow the call to super.close() which would permanently disable us.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.InputStream.close.

if an I/O error occurs.

isFinishedback to summary
public boolean isFinished()

Implements abstract jakarta.servlet.ServletInputStream.isFinished.

Doc from jakarta.servlet.ServletInputStream.isFinished.

Has the end of this InputStream been reached?

Returns:boolean

true if all the data has been read from the stream, else false

Annotations
@Override
isReadyback to summary
public boolean isReady()

Implements abstract jakarta.servlet.ServletInputStream.isReady.

Doc from jakarta.servlet.ServletInputStream.isReady.

Can data be read from this InputStream without blocking? Returns If this method is called and returns false, the container will invoke ReadListener#onDataAvailable() when data is available.

Returns:boolean

true if data can be read without blocking, else false

Annotations
@Override
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(final byte[] b) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

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

The first byte read is stored into element b[0], the next one into b[1], and so on. The number of bytes read is, at most, equal to the length of b. Let k be the number of bytes actually read; these bytes will be stored in elements b[0] through b[k-1], leaving elements b[k] through b[b.length-1] unaffected.

Parameters
b:byte[]

the buffer into which the data is read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs.
readback to summary
public int read(final byte[] b, final int off, final int len) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
readback to summary
public int read(final ByteBuffer b) 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
b: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
setReadListenerback to summary
public void setReadListener(ReadListener listener)

Implements abstract jakarta.servlet.ServletInputStream.setReadListener.

Doc from jakarta.servlet.ServletInputStream.setReadListener.

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.

Parameters
listener:ReadListener

The non-blocking IO read listener

Annotations
@Override
org.apache.catalina.connector back to summary

private Class CoyoteInputStream.PrivilegedAvailable

extends Object
implements PrivilegedExceptionAction<Integer>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.connector.CoyoteInputStream.PrivilegedAvailable
All Implemented Interfaces
java.security.PrivilegedExceptionAction

Field Summary

Modifier and TypeField and Description
private final InputBuffer

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Integer
run()

Implements java.security.PrivilegedExceptionAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

inputBufferback to summary
private final InputBuffer inputBuffer

Constructor Detail

PrivilegedAvailableback to summary
pack-priv PrivilegedAvailable(InputBuffer inputBuffer)

Method Detail

runback to summary
public Integer 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:Integer

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
org.apache.catalina.connector back to summary

private Class CoyoteInputStream.PrivilegedClose

extends Object
implements PrivilegedExceptionAction<Void>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.connector.CoyoteInputStream.PrivilegedClose
All Implemented Interfaces
java.security.PrivilegedExceptionAction

Field Summary

Modifier and TypeField and Description
private final InputBuffer

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Void
run()

Implements java.security.PrivilegedExceptionAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

inputBufferback to summary
private final InputBuffer inputBuffer

Constructor Detail

PrivilegedCloseback to summary
pack-priv PrivilegedClose(InputBuffer inputBuffer)

Method Detail

runback to summary
public Void 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:Void

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
org.apache.catalina.connector back to summary

private Class CoyoteInputStream.PrivilegedRead

extends Object
implements PrivilegedExceptionAction<Integer>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.connector.CoyoteInputStream.PrivilegedRead
All Implemented Interfaces
java.security.PrivilegedExceptionAction

Field Summary

Modifier and TypeField and Description
private final InputBuffer

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Integer
run()

Implements java.security.PrivilegedExceptionAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

inputBufferback to summary
private final InputBuffer inputBuffer

Constructor Detail

PrivilegedReadback to summary
pack-priv PrivilegedRead(InputBuffer inputBuffer)

Method Detail

runback to summary
public Integer 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:Integer

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
org.apache.catalina.connector back to summary

private Class CoyoteInputStream.PrivilegedReadArray

extends Object
implements PrivilegedExceptionAction<Integer>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.connector.CoyoteInputStream.PrivilegedReadArray
All Implemented Interfaces
java.security.PrivilegedExceptionAction

Field Summary

Modifier and TypeField and Description
private final byte[]
private final InputBuffer
private final int
private final int

Constructor Summary

AccessConstructor and Description
pack-priv
PrivilegedReadArray(InputBuffer inputBuffer, byte[] buf, int off, int len)

Method Summary

Modifier and TypeMethod and Description
public Integer
run()

Implements java.security.PrivilegedExceptionAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
private final byte[] buf
inputBufferback to summary
private final InputBuffer inputBuffer
lenback to summary
private final int len
offback to summary
private final int off

Constructor Detail

PrivilegedReadArrayback to summary
pack-priv PrivilegedReadArray(InputBuffer inputBuffer, byte[] buf, int off, int len)

Method Detail

runback to summary
public Integer 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:Integer

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
org.apache.catalina.connector back to summary

private Class CoyoteInputStream.PrivilegedReadBuffer

extends Object
implements PrivilegedExceptionAction<Integer>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.connector.CoyoteInputStream.PrivilegedReadBuffer
All Implemented Interfaces
java.security.PrivilegedExceptionAction

Field Summary

Modifier and TypeField and Description
private final ByteBuffer
private final InputBuffer

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Integer
run()

Implements java.security.PrivilegedExceptionAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bbback to summary
private final ByteBuffer bb
inputBufferback to summary
private final InputBuffer inputBuffer

Constructor Detail

PrivilegedReadBufferback to summary
pack-priv PrivilegedReadBuffer(InputBuffer inputBuffer, ByteBuffer bb)

Method Detail

runback to summary
public Integer 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:Integer

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