Package org.apache.sshd.sftp.client.impl
Class SftpDirEntryIterator
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.sftp.client.impl.SftpDirEntryIterator
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.Channel,java.util.Iterator<SftpClient.DirEntry>,SftpClientHolder
public class SftpDirEntryIterator extends AbstractLoggingBean implements SftpClientHolder, 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 Summary
Fields Modifier and Type Field Description private SftpClientclientprivate booleancloseOnFinishedprivate java.util.List<SftpClient.DirEntry>dirEntriesprivate SftpClient.HandledirHandleprivate java.lang.StringdirPathprivate java.util.concurrent.atomic.AtomicReference<java.lang.Boolean>eolIndicatorprivate intindexprivate java.util.concurrent.atomic.AtomicBooleanopen-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description SftpDirEntryIterator(SftpClient client, java.lang.String path)SftpDirEntryIterator(SftpClient client, java.lang.String path, SftpClient.Handle dirHandle, boolean closeOnFinished)SftpDirEntryIterator(SftpClient client, SftpClient.Handle dirHandle)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()SftpClientgetClient()SftpClient.HandlegetHandle()java.lang.StringgetPath()The remotely accessed directory pathbooleanhasNext()booleanisCloseOnFinished()booleanisOpen()protected java.util.List<SftpClient.DirEntry>load(SftpClient.Handle handle)SftpClient.DirEntrynext()voidremove()-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
-
-
-
Field Detail
-
eolIndicator
private final java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator
-
open
private final java.util.concurrent.atomic.AtomicBoolean open
-
client
private final SftpClient client
-
dirPath
private final java.lang.String dirPath
-
closeOnFinished
private final boolean closeOnFinished
-
dirHandle
private SftpClient.Handle dirHandle
-
dirEntries
private java.util.List<SftpClient.DirEntry> dirEntries
-
index
private int index
-
-
Constructor Detail
-
SftpDirEntryIterator
public SftpDirEntryIterator(SftpClient client, java.lang.String path) throws java.io.IOException
- Parameters:
client- TheSftpClientinstance to use for the iterationpath- The remote directory path- Throws:
java.io.IOException- If failed to gain access to the remote directory path
-
SftpDirEntryIterator
public SftpDirEntryIterator(SftpClient client, SftpClient.Handle dirHandle)
- Parameters:
client- TheSftpClientinstance to use for the iterationdirHandle- The directorySftpClient.Handleto use for listing the entries
-
SftpDirEntryIterator
public SftpDirEntryIterator(SftpClient client, java.lang.String path, SftpClient.Handle dirHandle, boolean closeOnFinished)
- Parameters:
client- TheSftpClientinstance to use for the iterationpath- A hint as to the remote directory path - used only for loggingdirHandle- The directorySftpClient.Handleto use for listing the entriescloseOnFinished- Iftruethen close the directory handle when all entries have been exhausted
-
-
Method Detail
-
getClient
public final SftpClient getClient()
- Specified by:
getClientin interfaceSftpClientHolder
-
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.Handleinstead of via a path - used only for logging
-
getHandle
public final SftpClient.Handle getHandle()
- Returns:
- The directory
SftpClient.Handleused to access the remote directory
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<SftpClient.DirEntry>
-
next
public SftpClient.DirEntry next()
- Specified by:
nextin interfacejava.util.Iterator<SftpClient.DirEntry>
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
isCloseOnFinished
public boolean isCloseOnFinished()
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
load
protected java.util.List<SftpClient.DirEntry> load(SftpClient.Handle handle)
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator<SftpClient.DirEntry>
-
-