Interface RecordWriter

All Superinterfaces:
AutoCloseable, Closeable, Flushable
All Known Subinterfaces:
TokenWriter
All Known Implementing Classes:
CborTokenWriter, JsonlTokenWriter, JsonTokenWriter, MsgPackTokenWriter

public interface RecordWriter extends Closeable, Flushable
Public low-level whole-value push generator over a Juneau-formatted document.

Format-neutral cursor that emits one whole-value record per write(Object) call. Single-rooted formats accept exactly one call (subsequent calls throw); multi-rooted formats (jsonl, csv, sse) emit one line / row / event per call.

Usage:

StringBuilder sb = new StringBuilder(); try (RecordWriter w = Json.DEFAULT.writeRecords(sb)) { w.write(bean); }

Streaming quality:
  • isStreaming() == true — O(1)-memory streaming. FULL-token formats return a cursor that is also a TokenWriter (the structural surface).
  • isStreaming() == false — buffered whole-value cursor (backed by RecordAdapter); write(Object) delegates to the format's existing serializer and the structural surface is not available.
Resource ownership:

Every RecordReader / RecordWriter produced by a factory method closes what it was handed — if the underlying input/output is Closeable, close() closes it. This contract is symmetric across all factory methods.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the writer, flushing any buffered output first.
    void
    Flushes any buffered output to the underlying stream.
    boolean
    Returns true if this cursor is an O(1)-memory streaming cursor, or false if it is a buffered whole-value cursor (backed by RecordAdapter).
    write(Object value)
    Emits one whole-value record.
  • Method Details

    • write

      Emits one whole-value record.
      Parameters:
      value - The value. May be null.
      Returns:
      This object.
      Throws:
      IOException - If a problem occurred writing to the underlying stream.
    • isStreaming

      boolean isStreaming()
      Returns true if this cursor is an O(1)-memory streaming cursor, or false if it is a buffered whole-value cursor (backed by RecordAdapter).
      Returns:
      true if this cursor streams; false if it buffers.
    • flush

      void flush() throws IOException
      Flushes any buffered output to the underlying stream.
      Specified by:
      flush in interface Flushable
      Throws:
      IOException - If a problem occurred flushing the underlying stream.
    • close

      void close() throws IOException
      Closes the writer, flushing any buffered output first.

      Implementations should be idempotent — closing a closed writer is a no-op.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException