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

public Class CoyoteOutputStream

extends ServletOutputStream
Class Inheritance
Imports
java.io.IOException, java.nio.ByteBuffer, java.util.Objects, jakarta.servlet.ServletOutputStream, .WriteListener, org.apache.tomcat.util.res.StringManager

Coyote implementation of the servlet output stream.
Authors
Costin Manolache, Remy Maucherat

Field Summary

Modifier and TypeField and Description
protected OutputBuffer
protected static final StringManager

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
private boolean

Returns:

true if this OutputStream is currently in non-blocking mode.
checkNonBlockingWrite
()

Checks for concurrent writes which are not permitted.

private void
checkRegisterForWrite()

Checks to see if there is data left in the Coyote output buffers (NOT the servlet output buffer) and if so registers the associated socket for write so the buffers will be emptied.

pack-priv void
clear()

Clear facade.

protected Object
clone()

Overrides java.lang.Object.clone.

Prevent cloning the facade.

public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Will send the buffer to the client.

public boolean
isReady()

Implements abstract jakarta.servlet.ServletOutputStream.isReady.

Checks if a non-blocking write will succeed.

public void
setWriteListener(WriteListener
The non-blocking IO write listener
listener
)

Implements abstract jakarta.servlet.ServletOutputStream.setWriteListener.

Sets the WriteListener for this ServletOutputStream and thereby switches to non-blocking IO.

public void
write(int
the byte.
i
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(byte[]
the data.
b
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.

public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

public void
Inherited from jakarta.servlet.ServletOutputStream:
printprintprintprintprintprintprintprintlnprintlnprintlnprintlnprintlnprintlnprintlnprintln

Field Detail

obback to summary
protected OutputBuffer ob
smback to summary
protected static final StringManager sm

Constructor Detail

CoyoteOutputStreamback to summary
protected CoyoteOutputStream(OutputBuffer ob)

Method Detail

checkNonBlockingWriteback to summary
private boolean checkNonBlockingWrite()

Checks for concurrent writes which are not permitted. This object has no state information so the call chain is CoyoteOutputStream->OutputBuffer->CoyoteResponse.

Returns:boolean

true if this OutputStream is currently in non-blocking mode.

checkRegisterForWriteback to summary
private void checkRegisterForWrite()

Checks to see if there is data left in the Coyote output buffers (NOT the servlet output buffer) and if so registers the associated socket for write so the buffers will be emptied. The container will take care of this. As far as the app is concerned, there is a non-blocking write in progress. It doesn't have visibility of whether the data is buffered in the socket buffer or the Coyote buffers.

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.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Will send the buffer to the client.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.OutputStream.flush.

if an I/O error occurs.

isReadyback to summary
public boolean isReady()

Implements abstract jakarta.servlet.ServletOutputStream.isReady.

Doc from jakarta.servlet.ServletOutputStream.isReady.

Checks if a non-blocking write will succeed. If this returns false, it will cause a callback to WriteListener#onWritePossible() when the buffer has emptied. If this method returns false no further data must be written until the container calls WriteListener#onWritePossible().

Returns:boolean

true if data can be written, else false

Annotations
@Override
setWriteListenerback to summary
public void setWriteListener(WriteListener listener)

Implements abstract jakarta.servlet.ServletOutputStream.setWriteListener.

Doc from jakarta.servlet.ServletOutputStream.setWriteListener.

Sets the WriteListener for this ServletOutputStream 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:WriteListener

The non-blocking IO write listener

Annotations
@Override
writeback to summary
public void write(int i) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
i:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] b) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Parameters
b:byte[]

the data.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
writeback to summary
public void write(ByteBuffer from) throws IOException