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>
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 Summary
Fields Modifier and Type Field Description private SftpClient
client
private boolean
closeOnFinished
private java.util.List<SftpClient.DirEntry>
dirEntries
private SftpClient.Handle
dirHandle
private java.lang.String
dirPath
private java.util.concurrent.atomic.AtomicReference<java.lang.Boolean>
eolIndicator
private int
index
private java.util.concurrent.atomic.AtomicBoolean
open
-
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 void
close()
SftpClient
getClient()
The client instanceSftpClient.Handle
getHandle()
java.lang.String
getPath()
The remotely accessed directory pathboolean
hasNext()
boolean
isCloseOnFinished()
boolean
isOpen()
protected java.util.List<SftpClient.DirEntry>
load(SftpClient.Handle handle)
SftpClient.DirEntry
next()
void
remove()
-
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
- TheSftpClient
instance 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
- TheSftpClient
instance to use for the iterationdirHandle
- The directorySftpClient.Handle
to use for listing the entries
-
SftpDirEntryIterator
public SftpDirEntryIterator(SftpClient client, java.lang.String path, SftpClient.Handle dirHandle, boolean closeOnFinished)
- Parameters:
client
- TheSftpClient
instance to use for the iterationpath
- A hint as to the remote directory path - used only for loggingdirHandle
- The directorySftpClient.Handle
to use for listing the entriescloseOnFinished
- Iftrue
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
-
getHandle
public final SftpClient.Handle getHandle()
- Returns:
- The directory
SftpClient.Handle
used to access the remote directory
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfacejava.util.Iterator<SftpClient.DirEntry>
-
next
public SftpClient.DirEntry next()
- Specified by:
next
in interfacejava.util.Iterator<SftpClient.DirEntry>
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfacejava.nio.channels.Channel
-
isCloseOnFinished
public boolean isCloseOnFinished()
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.nio.channels.Channel
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
load
protected java.util.List<SftpClient.DirEntry> load(SftpClient.Handle handle)
-
remove
public void remove()
- Specified by:
remove
in interfacejava.util.Iterator<SftpClient.DirEntry>
-
-