Class ServletOutputStreamImpl

  • All Implemented Interfaces:
    BufferWritableOutputStream, Closeable, Flushable, AutoCloseable

    public class ServletOutputStreamImpl
    extends jakarta.servlet.ServletOutputStream
    implements BufferWritableOutputStream
    This stream essentially has two modes. When it is being used in standard blocking mode then it will buffer in the pooled buffer. If the stream is closed before the buffer is full it will set a content-length header if one has not been explicitly set.

    If a content-length header was present when the stream was created then it will automatically close and flush itself once the appropriate amount of data has been written.

    Once the listener has been set it goes into async mode, and writes become non blocking. Most methods have two different code paths, based on if the listener has been set or not

    Once the write listener has been set operations must only be invoked on this stream from the write listener callback. Attempting to invoke from a different thread will result in an IllegalStateException.

    Async listener tasks are queued in the AsyncContextImpl. At most one listener can be active at one time, which simplifies the thread safety requirements.

    Author:
    Stuart Douglas