Interface JsonOutput

All Superinterfaces:
AutoCloseable, Closeable

public interface JsonOutput extends Closeable
Output that can be aware of server content chunking.

We can use an implementation of JsonOutput such that it can make use of the underlying buffer used by avaje-jsonb, using writeLast(byte[], int, int) to know if the content is complete (and typically can be written directly as fixed content) or if the content is still being written (and potentially written by an http server as chunked content).

Typically, for HTTP servers that can send output using fixed length or chunked.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Flush the underlying OutputStream.
    static JsonOutput
    of(io.helidon.webserver.http.ServerResponse nimaServerResponse)
    Create for Nima ServerResponse.
    static JsonOutput
    of(OutputStream outputStream)
    Deprecated.
    static JsonOutput
    ofStream(OutputStream outputStream)
    Create as a simple wrapper for OutputStream.
    Return the underlying OutputStream.
    void
    write(byte[] content, int offset, int length)
    Write the content to the underlying output stream.
    default void
    writeLast(byte[] content, int offset, int length)
    Write the last content to the underlying output stream.

    Methods inherited from interface java.io.Closeable

    close
  • Method Details

    • ofStream

      static JsonOutput ofStream(OutputStream outputStream)
      Create as a simple wrapper for OutputStream.
    • of

      @Deprecated static JsonOutput of(OutputStream outputStream)
      Deprecated.
    • of

      static JsonOutput of(io.helidon.webserver.http.ServerResponse nimaServerResponse)
      Create for Nima ServerResponse.
    • write

      void write(byte[] content, int offset, int length) throws IOException
      Write the content to the underlying output stream.
      Throws:
      IOException
    • writeLast

      default void writeLast(byte[] content, int offset, int length) throws IOException
      Write the last content to the underlying output stream.

      Given that this is known to be the last content written an implementation can make use of this to optimise for sending as fixed length content.

      Throws:
      IOException
    • flush

      void flush() throws IOException
      Flush the underlying OutputStream.
      Throws:
      IOException
    • unwrapOutputStream

      OutputStream unwrapOutputStream()
      Return the underlying OutputStream.

      This is used for Jsonb adapters (Jackson) that can't support writeLast() semantics.