public static interface Source.Reader<T>
extends java.lang.AutoCloseable
This interface is deliberately distinct from Iterator because
the current model tends to be easier to program and more efficient in practice
for iterating over sources such as files, databases etc. (rather than pure collections).
To read a Reader:
for (boolean available = reader.start(); available; available = reader.advance()) {
T item = reader.getCurrent();
...
}
Note: this interface is work-in-progress and may change.
| Modifier and Type | Method and Description |
|---|---|
boolean |
advance()
Advances the reader to the next valid record.
|
void |
close()
Closes the reader.
|
T |
getCurrent()
|
Source<T> |
getCurrentSource()
Returns a
Source describing the same input that this Reader reads
(including items already read). |
Instant |
getCurrentTimestamp()
Returns the timestamp associated with the current data item.
|
boolean |
start()
Initializes the reader and advances the reader to the first record.
|
boolean start()
throws java.io.IOException
This method should be called exactly once. The invocation should occur prior to calling
advance() or getCurrent(). This method may perform expensive operations that
are needed to initialize the reader.
true if a record was read, false if we're at the end of input.java.io.IOExceptionboolean advance()
throws java.io.IOException
getCurrent() call.true if a record was read, false if we're at the end of input.java.io.IOExceptionT getCurrent() throws java.util.NoSuchElementException
Instant getCurrentTimestamp() throws java.util.NoSuchElementException
If the source does not support timestamps, this should return
BoundedWindow.TIMESTAMP_MIN_VALUE.
java.util.NoSuchElementExceptionvoid close()
throws java.io.IOException
close in interface java.lang.AutoCloseablejava.io.IOException