Class HttpOutput

java.lang.Object
java.io.OutputStream
jakarta.servlet.ServletOutputStream
org.eclipse.jetty.ee11.servlet.HttpOutput
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class HttpOutput extends jakarta.servlet.ServletOutputStream

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.

  • Constructor Details

  • Method Details

    • isWritten

      public boolean isWritten()
      Returns:
      True if any content has been written via the HttpServletResponse API.
    • getWritten

      public long getWritten()
      Returns:
      The bytes written via the HttpServletResponse API. This may differ from the bytes reported by Response.getContentBytesWritten(Response) due to buffering, compression, other interception or writes that bypass the servlet API.
    • setApplicationContentLength

      public void setApplicationContentLength(long len)
      Set the content-length as set by the application. This may not be the actual content length if compression or similar handlers are used.
      Parameters:
      len - The content-length as set by the application.
    • getApplicationContentLength

      public long getApplicationContentLength()
      Get the content-length as set by the application. This may not be the actual content length if compression or similar handlers are used.
      Returns:
      The content-length as set by the application.
    • isContentIncomplete

      public boolean isContentIncomplete()
      Returns:
      true if a Content-Length has been set and insufficient content has been written.
    • reopen

      public void reopen()
    • softClose

      public void softClose()
    • takeContentAndClose

      public ByteBuffer takeContentAndClose()
    • complete

      public void complete(Callback callback)
      This method is invoked for the COMPLETE action handling in HttpChannel.handle. The callback passed typically will call completed to finish the request cycle and so may need to asynchronously wait for: a pending/blocked operation to finish and then either an async close or wait for an application close to complete.
      Parameters:
      callback - The callback to complete when writing the output is complete.
    • completed

      public void completed(Throwable ignored)
      Called to indicate that the request cycle has been completed.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class jakarta.servlet.ServletOutputStream
      Throws:
      IOException
    • getByteBuffer

      public ByteBuffer getByteBuffer()
    • isClosed

      public boolean isClosed()
    • isAsync

      public boolean isAsync()
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(ByteBuffer buffer) throws IOException
      Overrides:
      write in class jakarta.servlet.ServletOutputStream
      Throws:
      IOException
    • write

      public void write(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • print

      public void print(String s) throws IOException
      Overrides:
      print in class jakarta.servlet.ServletOutputStream
      Throws:
      IOException
    • println

      public void println(String s) throws IOException
      Overrides:
      println in class jakarta.servlet.ServletOutputStream
      Throws:
      IOException
    • sendContent

      public void sendContent(ByteBuffer content) throws IOException
      Blocking send of whole content.
      Parameters:
      content - The whole content to send
      Throws:
      IOException - if the send fails
    • sendContent

      public void sendContent(InputStream in) throws IOException
      Blocking send of stream content.
      Parameters:
      in - The stream content to send
      Throws:
      IOException - if the send fails
    • sendContent

      public void sendContent(ReadableByteChannel in) throws IOException
      Blocking send of channel content.
      Parameters:
      in - The channel content to send
      Throws:
      IOException - if the send fails
    • sendContent

      public void sendContent(ByteBuffer content, Callback callback)
      Asynchronous send of whole content.
      Parameters:
      content - The whole content to send
      callback - The callback to use to notify success or failure
    • sendContent

      public void sendContent(InputStream in, Callback callback)
      Asynchronous send of stream content. The stream will be closed after reading all content.
      Parameters:
      in - The stream content to send
      callback - The callback to use to notify success or failure
    • sendContent

      public void sendContent(ReadableByteChannel in, Callback callback)
      Asynchronous send of channel content. The channel will be closed after reading all content.
      Parameters:
      in - The channel content to send
      callback - The callback to use to notify success or failure
    • getBufferSize

      public int getBufferSize()
    • setBufferSize

      public void setBufferSize(int size)
    • recycle

      public void recycle()
    • resetBuffer

      public void resetBuffer()
    • setWriteListener

      public void setWriteListener(jakarta.servlet.WriteListener writeListener)
      Specified by:
      setWriteListener in class jakarta.servlet.ServletOutputStream
    • isReady

      public boolean isReady()
      Specified by:
      isReady in class jakarta.servlet.ServletOutputStream
    • writeCallback

      public void writeCallback()
    • toString

      public String toString()
      Overrides:
      toString in class Object