Interface IObjectStream<T>
Reads Objects from a stream.
Design Decision:
This interface provides a means for iterating over the
objects in a stream, it does not implement IEnumerator<T> or
IEnumerable<T> because:
Iterator.next()andIterator.hasNext()are declared as throwing no checked exceptions. Thus the IOExceptions thrown by Read() would have to be wrapped in runtime exceptions, and the compiler would be unable to force users of this code to catch such exceptions.- Implementing an enumerable would mean either silently calling Reset() to guarantee that all items were always seen on each iteration, or documenting that it only iterates over the remaining elements of the IObjectStream<T>. In either case, users not reading the documentation carefully might run into unexpected behavior.
public interface IObjectStream<out T> : IDisposable
Type Parameters
T
- Inherited Members
Methods
Read()
Returns the next object. Calling this method repeatedly until it returns
null will return each object from the underlying source exactly once.
T Read()
Returns
- T
the next object or
nullto signal that the stream is exhausted
Exceptions
- IOException
if there is an error during reading
Reset()
Repositions 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.
void Reset()
Exceptions
- IOException
if there is an error during resetting the stream
- NotSupportedException
if reset is not supported on this stream