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 theDirectoryStream
interface 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 protected
AbstractDirectoryStream(DirectoryStream.Filter<? super T> filter)
Creates a newDirectoryStream
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
protected abstract T
getNext()
Returns the next element in iteration.Iterator<T>
iterator()
protected void
setupIteration()
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:
close
in interfaceAutoCloseable
- Specified by:
close
in 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
null
if there is no more next element. - Throws:
IOException
- If the next element could not be retrieved.
-
-