- All Superinterfaces:
- All Known Subinterfaces:
- All Known Implementing Classes:
public interface ObjectStream<T> extends AutoCloseableReads
Objects from a stream.
Iterator.hasNext()are declared as throwing no checked exceptions. Thus the
IOExceptions thrown by
read()would have to be wrapped in
RuntimeExceptions, and the compiler would be unable to force users of this code to catch such exceptions.
Iterablewould mean either silently calling
reset()to guarantee that all items were always seen on each iteration, or documenting that the Iterable only iterates over the remaining elements of the ObjectStream. In either case, users not reading the documentation carefully might run into unexpected behavior.
- See Also:
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description
ObjectStreamand releases all allocated resources.
read()Returns the next object.
reset()Repositions the stream at the beginning and the previously seen object sequence will be repeated exactly.
T read() throws IOExceptionReturns the next object. Calling this method repeatedly until it returns null will return each object from the underlying source exactly once.
- the next object or null to signal that the stream is exhausted
IOException- if there is an error during reading
default void reset() throws IOException, UnsupportedOperationExceptionRepositions the stream at the beginning and the previously seen object sequence will be repeated exactly. This method can be used to re-read the stream if multiple passes over the objects are required. The implementation of this method is optional.