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 do not instantiate implementations directly.
Instead, use the containing dataset's Dataset#newReader()
method to
get an appropriate implementation. newReader
returns an instance of
this interface. Invoke hasNext()
and next()
as
required, and 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 standard try/finally
pattern to ensure that these resources are properly freed when the reader is
exhausted or no longer useful. Avoid relying on implementations to
automatically invoke the close()
method on object finalization.
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;
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.
No further operations of this interface (other than additional calls to this method) can be performed; however, you can choose to permit other method calls in your own implementations.
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