Class 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 the DirectoryStream 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 that iterator() is only called once.

    Subclasses often only need to implement getNext(). Optionally, if they need perform setup steps before iteration, they should override setupIteration() as well.

    Author:
    Rob Spoor
    • Constructor Detail

      • AbstractDirectoryStream

        protected AbstractDirectoryStream​(DirectoryStream.Filter<? super T> filter)
        Creates a new DirectoryStream.
        Parameters:
        filter - The optional filter to use.
    • Method Detail

      • 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.