Class SftpDirEntryIterator

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel, java.util.Iterator<SftpClient.DirEntry>

    public class SftpDirEntryIterator
    extends AbstractLoggingBean
    implements java.util.Iterator<SftpClient.DirEntry>, java.nio.channels.Channel
    Iterates over the available directory entries for a given path. Note: if the iteration is carried out until no more entries are available, then no need to close the iterator. Otherwise, it is recommended to close it so as to release the internal handle.
    • Field Detail

      • eolIndicator

        private final java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator
      • open

        private final java.util.concurrent.atomic.AtomicBoolean open
      • dirPath

        private final java.lang.String dirPath
      • closeOnFinished

        private final boolean closeOnFinished
      • index

        private int index
    • Constructor Detail

      • SftpDirEntryIterator

        public SftpDirEntryIterator​(SftpClient client,
                                    java.lang.String path)
                             throws java.io.IOException
        Parameters:
        client - The SftpClient instance to use for the iteration
        path - The remote directory path
        Throws:
        java.io.IOException - If failed to gain access to the remote directory path
      • SftpDirEntryIterator

        public SftpDirEntryIterator​(SftpClient client,
                                    java.lang.String path,
                                    SftpClient.Handle dirHandle,
                                    boolean closeOnFinished)
        Parameters:
        client - The SftpClient instance to use for the iteration
        path - A hint as to the remote directory path - used only for logging
        dirHandle - The directory SftpClient.Handle to use for listing the entries
        closeOnFinished - If true then close the directory handle when all entries have been exhausted
    • Method Detail

      • getClient

        public final SftpClient getClient()
        The client instance
        Returns:
        SftpClient instance used to access the remote folder
      • getPath

        public final java.lang.String getPath()
        The remotely accessed directory path
        Returns:
        Remote directory hint - may be the handle's value if accessed directly via a SftpClient.Handle instead of via a path - used only for logging
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<SftpClient.DirEntry>
      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • isCloseOnFinished

        public boolean isCloseOnFinished()
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • remove

        public void remove()
        Specified by:
        remove in interface java.util.Iterator<SftpClient.DirEntry>