Class StreamingArrayRecord
TokenReader / TokenWriter to
the array-element record-stream contract. Memory does not scale with the number of array
elements — reading binds one element at a time; writing emits one element at a time.
For the reader: the wrapper opens an outer array via the cursor's TokenReader.next(),
yields elements via TokenReader.read(Class) until TokenReader.canRead() returns
false (end of array), then advances past the closing ] on close.
For the writer: the wrapper opens an outer array via TokenWriter.startArray(),
forwards each write(...) call to
TokenWriter.object(Object), and emits the closing ] via
TokenWriter.endArray() on close.
Used by FULL-capability formats whose token cursor genuinely streams (json, json5, cbor, etc.).
For PARTIAL formats whose token surface doesn't exist, see
RecordAdapter.arrayReader(ParserSession, Object) / RecordAdapter.arrayWriter(org.apache.juneau.marshall.serializer.SerializerSession, java.lang.Object), which
are buffered.
-
Method Summary
Modifier and TypeMethodDescriptionstatic RecordReaderreader(TokenReader cursor) Wraps aTokenReaderas a streaming array-elementRecordReader.static RecordWriterwriter(TokenWriter cursor) Wraps aTokenWriteras a streaming array-elementRecordWriter.
-
Method Details
-
reader
Wraps aTokenReaderas a streaming array-elementRecordReader.The wrapper assumes the cursor is positioned at the start of an array on the wire. It consumes the opening
TokenType.START_ARRAYon construction and the closingTokenType.END_ARRAYonclose().- Parameters:
cursor- The token reader to wrap. Must not benull . Owned by the returned RecordReader; closing the RecordReader closes the cursor.- Returns:
- A streaming array-element
RecordReader. - Throws:
IOException- If a problem occurred reading the underlying input.ParseException- If the input is not a JSON-style array.
-
writer
Wraps aTokenWriteras a streaming array-elementRecordWriter.The wrapper emits the opening array on construction. Each
RecordWriter.write(Object)call appends one array element viaTokenWriter.object(Object).close()emits the closing array bracket and closes the underlying cursor.- Parameters:
cursor- The token writer to wrap. Must not benull . Owned by the returned RecordWriter; closing the RecordWriter closes the cursor.- Returns:
- A streaming array-element
RecordWriter. - Throws:
IOException- If a problem occurred writing to the underlying output.
-