Package com.github.robtimus.filesystems
Class AbstractDirectoryStream<T>
- java.lang.Object
-
- com.github.robtimus.filesystems.AbstractDirectoryStream<T>
-
- Type Parameters:
T- The type of element returned by the iterator.
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<T>,DirectoryStream<T>
public abstract class AbstractDirectoryStream<T> extends Object implements DirectoryStream<T>
This class provides a skeletal implementation of theDirectoryStreaminterface to minimize the effort required to implement this interface. It will take care of ending iteration when the stream is closed, and making sure thatiterator()is only called once.Subclasses often only need to implement
getNext(). Optionally, if they need perform setup steps before iteration, they should overridesetupIteration()as well.- Author:
- Rob Spoor
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface java.nio.file.DirectoryStream
DirectoryStream.Filter<T extends Object>
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractDirectoryStream(DirectoryStream.Filter<? super T> filter)Creates a newDirectoryStream.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()protected abstract TgetNext()Returns the next element in iteration.Iterator<T>iterator()protected voidsetupIteration()Performs the necessary steps to setup iteration.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
AbstractDirectoryStream
protected AbstractDirectoryStream(DirectoryStream.Filter<? super T> filter)
Creates a newDirectoryStream.- Parameters:
filter- The optional filter to use.
-
-
Method Detail
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
setupIteration
protected void setupIteration()
Performs the necessary steps to setup iteration. The default implementation does nothing.
-
getNext
protected abstract T getNext() throws IOException
Returns the next element in iteration.- Returns:
- The next element in iteration, or
nullif there is no more next element. - Throws:
IOException- If the next element could not be retrieved.
-
-