Class AbstractCloseableIterator<E>

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.util.Iterator<E>
    Direct Known Subclasses:
    LookAheadIterator

    public abstract class AbstractCloseableIterator<E>
    extends java.lang.Object
    implements java.util.Iterator<E>, java.io.Closeable
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.atomic.AtomicBoolean closed
      Flag indicating whether this iteration has been closed.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Calls handleClose() upon first call and makes sure this method gets called only once.
      protected void handleAlreadyClosed()  
      protected void handleClose()
      Called by close() when it is called for the first time.
      boolean isClosed()
      Checks whether this Iterator has been closed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, hasNext, next, remove
    • Field Detail

      • closed

        private final java.util.concurrent.atomic.AtomicBoolean closed
        Flag indicating whether this iteration has been closed.
    • Constructor Detail

      • AbstractCloseableIterator

        public AbstractCloseableIterator()
    • Method Detail

      • isClosed

        public final boolean isClosed()
        Checks whether this Iterator has been closed.
        Returns:
        true if the Iterator has been closed, false otherwise.
      • close

        public final void close()
                         throws java.io.IOException
        Calls handleClose() upon first call and makes sure this method gets called only once.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • handleClose

        protected void handleClose()
                            throws java.io.IOException
        Called by close() when it is called for the first time. This method is only called once on each iteration. By default, this method does nothing.
        Throws:
        X
        java.io.IOException
      • handleAlreadyClosed

        protected void handleAlreadyClosed()
                                    throws java.io.IOException
        Throws:
        java.io.IOException