Top Description Inners Fields Constructors Methods
org.eclipse.jetty.ee10.servlet

public Class HttpOutput

extends ServletOutputStream
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable
Imports
java.io.IOException, .InputStream, java.nio.ByteBuffer, .CharBuffer, java.nio.channels.ReadableByteChannel, .WritePendingException, java.nio.charset.Charset, .CharsetEncoder, .CoderResult, .CodingErrorAction, java.util.concurrent.CancellationException, .TimeUnit, jakarta.servlet.RequestDispatcher, .ServletOutputStream, .ServletRequest, .ServletResponse, .WriteListener, org.eclipse.jetty.io.ByteBufferPool, .Content, .EofException, .RetainableByteBuffer, org.eclipse.jetty.server.HttpConfiguration, .Response, org.eclipse.jetty.util.Blocker, .BufferUtil, .Callback, .ExceptionUtil, .IO, .IteratingCallback, .NanoTime, org.eclipse.jetty.util.thread.AutoLock, org.slf4j.Logger, .LoggerFactory

HttpOutput implements ServletOutputStream as required by the Servlet specification.

HttpOutput buffers content written by the application until a further write will overflow the buffer, at which point it triggers a commit of the response.

HttpOutput can be closed and reopened, to allow requests included via RequestDispatcher#include(ServletRequest, ServletResponse) to close the stream, to be reopened after the inclusion ends.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
HttpOutput.ApiState

The API State which combines with the output State:

             OPEN/BLOCKING---last----------------------------+                      CLOSED/BLOCKING
            /   |    ^                                        \                         ^  ^
           /    w    |                                         \                       /   |
          /     |   owc   +--owcL------------------->--owcL-----\---------------------+    |
         |      v    |   /                         /             V                         |
        swl  OPEN/BLOCKED----last---->CLOSE/BLOCKED----owc----->CLOSING/BLOCKED--owcL------+
         |
          \
           \
            V
         +-->OPEN/READY------last---------------------------+
        /    ^    |                                          \
       /    /     w                                           \
      |    /      |       +--owcL------------------->--owcL----\---------------------------+
      |   /       v      /                         /            V                          |
      | irt  OPEN/PENDING----last---->CLOSE/PENDING----owc---->CLOSING/PENDING--owcL----+  |
      |   \  /    |                        |                    ^     |                 |  |
     owc   \/    owc                      irf                  /     irf                |  |
      |    /\     |                        |                  /       |                 |  |
      |   /  \    V                        |                 /        |                 V  V
      | irf  OPEN/ASYNC------last----------|----------------+         |             CLOSED/ASYNC
      |   \                                |                          |                 ^  ^
       \   \                               |                          |                 |  |
        \   \                              |                          |                 |  |
         \   v                             v                          v                 |  |
          +--OPEN/UNREADY----last---->CLOSE/UNREADY----owc----->CLOSING/UNREADY--owcL---+  |
                         \                         \                                       |
                          +--owcL------------------->--owcL--------------------------------+

     swl  : setWriteListener
     w    : write
     owc  : onWriteComplete last == false
     owcL : onWriteComplete last == true
     irf  : isReady() == false
     irt  : isReady() == true
     last : close() or complete(Callback) or write of known last content
    
private class
private class
private abstract class
private class
private class
HttpOutput.InputStreamWritingCB

An iterating callback that will take content from an InputStream and write it to this HttpOutput.

private abstract class
private class
HttpOutput.ReadableByteChannelWritingCB

An iterating callback that will take content from a ReadableByteChannel and write it to this HttpOutput.

pack-priv static enum
HttpOutput.State

The output state

private class

Field Summary

Modifier and TypeField and Description
private RetainableByteBuffer
private HttpOutput.ApiState
private int
private final ServletChannelState
private Callback
private int
private static final ThreadLocal<CharsetEncoder>
private long
private long
private volatile Throwable
private final ServletChannel
private boolean
private HttpOutput.State
private final Blocker.Shared
private WriteListener
private long
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private RetainableByteBuffer
private void
channelWrite(ByteBuffer content, boolean complete)

private void
channelWrite(ByteBuffer content, boolean last, Callback callback)

private void
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
complete(Callback
The callback to complete when writing the output is complete.
callback
)

This method is invoked for the COMPLETE action handling in HttpChannel.handle.

public void
completed(Throwable failure)

Called to indicate that the request cycle has been completed.

public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.

public int
public ByteBuffer
public long
getWritten()

Returns: The bytes written via the jakarta.servlet.http.HttpServletResponse API.

public boolean
public boolean
public boolean
isReady()

Implements abstract jakarta.servlet.ServletOutputStream.isReady.

Returns true if data can be written without blocking else returns false.

public boolean
isWritten()

Returns: True if any content has been written via the jakarta.servlet.http.HttpServletResponse API.

private int
public void
onFlushed(long
the number of bytes flushed
bytes
)

Invoked when bytes have been flushed to the network.

private void
onWriteComplete(boolean last, Throwable failure)

private boolean
prepareSendContent(int len, Callback callback)

public void
println(String
the String to write to the client
s
)

Overrides jakarta.servlet.ServletOutputStream.println.

Writes a String to the client, followed by a carriage return-line feed (CRLF).

public void
private void
public void
public void
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

public void
sendContent(ByteBuffer
The whole content to send
content
)

Blocking send of whole content.

public void
sendContent(InputStream
The stream content to send
in
)

Blocking send of stream content.

public void
sendContent(ReadableByteChannel
The channel content to send
in
)

Blocking send of channel content.

public void
sendContent(ByteBuffer
The whole content to send
content
,
final Callback
The callback to use to notify success or failure
callback
)

Asynchronous send of whole content.

public void
sendContent(InputStream
The stream content to send
in
,
Callback
The callback to use to notify success or failure
callback
)

Asynchronous send of stream content.

public void
sendContent(ReadableByteChannel
The channel content to send
in
,
Callback
The callback to use to notify success or failure
callback
)

Asynchronous send of channel content.

public void
setBufferSize(int size)

public void
setWriteListener(WriteListener
the WriteListener that should be notified when it's possible to write
writeListener
)

Implements abstract jakarta.servlet.ServletOutputStream.setWriteListener.

Instructs the ServletOutputStream to invoke the provided WriteListener when it is possible to write

public void
private String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private boolean
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
write(ByteBuffer buffer)

public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

Inherited from jakarta.servlet.ServletOutputStream:
printprintprintprintprintprintprintlnprintlnprintlnprintlnprintlnprintlnprintln