E
- The type of entity produced by this reader.public interface DatasetReader<E>
extends java.util.Iterator<E>, java.lang.Iterable<E>, java.io.Closeable
A stream-oriented dataset reader.
Implementations of this interface read data from a Dataset
.
Readers are use-once objects that read from the underlying storage system to
produce deserialized entities of type E
.
Normally, you are not expected to instantiate implementations directly.
Instead, use the containing dataset's Dataset#newReader()
method to
get an appropriate implementation. newReader
returns an instance of
this interface. You invoke hasNext()
and next()
as
necessary, then close()
when you are done or no more data exists.
Implementations can hold system resources until the close()
method
is called, so you must follow the normal try/finally
pattern to ensure these resources are properly freed when the reader is
exhausted or no longer useful. You should not rely on implementations
automatically invoking the close()
method upon object finalization
(although you are free to do so, if you choose). Your implementations must
silently ignore multiple invocations of close()
, as well as a close
of an unopened reader.
If any method throws an exception, the reader is no longer valid. The
only method that you can call after an exception is close()
.
Implementations of DatasetReader
are not required to be thread-safe;
that is, the behavior when accessing a single instance from multiple threads
is undefined.
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the reader and release any system resources.
|
boolean |
hasNext()
Test the reader to see if additional entities can be read.
|
boolean |
isOpen()
Test whether the reader is currently open.
|
E |
next()
Fetch the next entity from the reader.
|
void |
remove()
Remove from the underlying collection the last element returned by the
reader (optional).
|
boolean hasNext()
hasNext
in interface java.util.Iterator<E>
true
if additional entities exist, false
otherwise.DatasetReaderException
E next()
Fetch the next entity from the reader.
Calling this method when no additional data exists is illegal; you should
use hasNext()
to test if a call to read another entity will
succeed.
Implementations of this method can block.
next
in interface java.util.Iterator<E>
E
.DatasetReaderException
java.util.NoSuchElementException
void remove()
Remove from the underlying collection the last element returned by the
reader (optional). This has the same semantics as
Iterator.remove()
.
For most applications, you do not need to implement remove
.
remove
in interface java.util.Iterator<E>
void close()
Close the reader and release any system resources.
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
DatasetReaderException
boolean isOpen()
Test whether the reader is currently open.
true
if the reader is open, false
otherwiseDatasetReaderException