Class RecordStreamBody

java.lang.Object
org.apache.juneau.rest.client.classic.RecordStreamBody

public final class RecordStreamBody extends Object
Wrapper that lets a caller pass a Consumer<RecordWriter> or Consumer<TokenWriter> as the body of a @RemoteOp request.

The framework resolves the matching serializer for the request's Content-Type, opens a writer of the appropriate kind, and hands it to the caller's consumer. When the consumer returns, the writer is closed and the request body is dispatched.

Usage:

@Remote public interface MyApi { @RemotePost("/bulk-upload") void upload(@Content RecordStreamBody body); } // Caller api.upload(RecordStreamBody.records(w -> { for (Bean b : source()) w.write(b); }));

  • Method Details

    • records

      public static RecordStreamBody records(Consumer<RecordWriter> consumer)
      Creates a body that streams via a RecordWriter (whole-value record cursor).
      Parameters:
      consumer - The callback that emits records. Must not be null.
      Returns:
      A new body wrapper.
    • token

      public static RecordStreamBody token(Consumer<TokenWriter> consumer)
      Creates a body that streams via a TokenWriter (fine-grained structural cursor).
      Parameters:
      consumer - The callback that emits structural events. Must not be null.
      Returns:
      A new body wrapper.
    • getConsumer

      public Consumer<?> getConsumer()
      Returns:
      The caller's consumer (typed as Consumer<RecordWriter> or Consumer<TokenWriter>).
    • getWriterKind

      public Class<?> getWriterKind()
      Returns:
      Either RecordWriter.class or TokenWriter.class.