Interface RecordReader
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Subinterfaces:
TokenReader
- All Known Implementing Classes:
CborTokenReader,Json5lTokenReader,Json5TokenReader,JsonlTokenReader,JsonTokenReader,MsgPackTokenReader
Format-neutral cursor that yields one whole-value record per read(Class) call. Single-rooted
formats (json, xml, bson, yaml, ...) degenerate to a one-record stream; multi-rooted formats
(jsonl, csv, sse) expose each line / row / event as a separate record.
Usage:
Streaming quality:
isStreaming()==true — O(1)-memory streaming. FULL-token formats return a cursor that is also aTokenReader(the structural surface).isStreaming()==false — buffered whole-value cursor (backed byRecordAdapter);read(Class)delegates to the format's existing parser and the structural surface is not available.
See Also:
RecordWriter— the push-side counterpart.TokenReader— structural extension for FULL-capability formats.- Serializers and Parsers
-
Method Summary
Modifier and TypeMethodDescriptionbooleancanRead()Returnstrue ifread(Class)can be called to produce another record.voidclose()Closes the underlying stream.booleanReturnstrue if this cursor is an O(1)-memory streaming cursor, orfalse if it is a buffered whole-value cursor (backed byRecordAdapter).default <T> Iterator<T>Returns anIteratorview that yields each remaining record bound to the requested type.<T> TReads and returns the next record bound to the requested type.<T> TSame asread(Class)but accepts a parameterizedTypeand optional type arguments (the same shape asParser.read(Object, Type, Type...)).<T> TSame asread(Class)but accepts a pre-resolvedClassMeta.default <T> Stream<T>Returns aStreamview that yields each remaining record bound to the requested type.
-
Method Details
-
canRead
Returnstrue ifread(Class)can be called to produce another record.Single-rooted formats return
true exactly once (for the root value), thenfalse after the value has been consumed. Multi-rooted formats returntrue once per remaining record on the wire.- Returns:
true if a record is available;false at end of stream.- Throws:
IOException- If a problem occurred peeking at the underlying stream.ParseException- If the input is malformed for the format.
-
read
Reads and returns the next record bound to the requested type.- Type Parameters:
T- The expected return type.- Parameters:
type- The target Java type.- Returns:
- The bound POJO.
- Throws:
IOException- If a problem occurred reading from the underlying stream.ParseException- If the input is malformed for the format or cannot be bound to the type.IllegalStateException- IfcanRead()returnedfalse .
-
read
Same asread(Class)but accepts a pre-resolvedClassMeta.- Type Parameters:
T- The expected return type.- Parameters:
type- The target type.- Returns:
- The bound POJO.
- Throws:
IOException- If a problem occurred reading from the underlying stream.ParseException- If the input is malformed or cannot be bound to the type.
-
read
Same asread(Class)but accepts a parameterizedTypeand optional type arguments (the same shape asParser.read(Object, Type, Type...)).- Type Parameters:
T- The expected return type.- Parameters:
type- The target type.args- Optional type arguments for parameterized types.- Returns:
- The bound POJO.
- Throws:
IOException- If a problem occurred reading from the underlying stream.ParseException- If the input is malformed or cannot be bound to the type.
-
iterator
Returns anIteratorview that yields each remaining record bound to the requested type.The iterator drains from this cursor; consuming both surfaces concurrently is not supported.
Checked
IOException/ParseExceptionthrown by the underlying cursor are wrapped in anRuntimeParseException(carrying the typed cause) so they can surface through theIteratorAPI.- Type Parameters:
T- The element type.- Parameters:
type- The element type.- Returns:
- An iterator over the remaining records.
-
stream
Returns aStreamview that yields each remaining record bound to the requested type.- Type Parameters:
T- The element type.- Parameters:
type- The element type.- Returns:
- A stream over the remaining records.
-
isStreaming
boolean isStreaming()Returnstrue if this cursor is an O(1)-memory streaming cursor, orfalse if it is a buffered whole-value cursor (backed byRecordAdapter).- Returns:
true if this cursor streams;false if it buffers.
-
close
Closes the underlying stream.Implementations should be idempotent — closing a closed reader is a no-op.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-