Class GrpcWebOutputStream

java.lang.Object
java.io.OutputStream
jakarta.servlet.ServletOutputStream
io.grpc.servlet.jakarta.web.GrpcWebOutputStream
All Implemented Interfaces:
jakarta.servlet.WriteListener, Closeable, Flushable, AutoCloseable, EventListener

public class GrpcWebOutputStream extends jakarta.servlet.ServletOutputStream implements jakarta.servlet.WriteListener
Wraps the usual ServletOutputStream so as to allow downstream writers to use it according to the servlet spec, but still make it easy to write trailers as a payload instead of using HTTP trailers at the end of a stream.
  • Constructor Details

    • GrpcWebOutputStream

      public GrpcWebOutputStream(jakarta.servlet.ServletOutputStream wrapped)
  • Method Details

    • isReady

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

      public void writeAndCloseWhenReady(byte[] bytes, Runnable close)
      Internal helper method to correctly write the given bytes, then complete the stream.
      Parameters:
      bytes - the bytes to write once writing is possible
      close - a Runnable to invoke once this write is complete
    • setWriteListener

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

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

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

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

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

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException
    • onWritePossible

      public void onWritePossible() throws IOException
      Specified by:
      onWritePossible in interface jakarta.servlet.WriteListener
      Throws:
      IOException
    • onError

      public void onError(Throwable t)
      Specified by:
      onError in interface jakarta.servlet.WriteListener