Top Description Fields Constructors Methods
org.apache.sshd.sftp.client.impl

public Class SftpDirEntryIterator

extends AbstractLoggingBean
implements SftpClientHolder, Iterator<SftpClient.DirEntry>, Channel
Class Inheritance
All Implemented Interfaces
java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.util.Iterator, org.apache.sshd.sftp.client.SftpClientHolder
Imports
java.io.Closeable, .IOException, .UncheckedIOException, java.nio.channels.Channel, java.util.Iterator, .List, .Objects, java.util.concurrent.atomic.AtomicBoolean, .AtomicReference, org.apache.sshd.common.util.ValidateUtils, org.apache.sshd.common.util.logging.AbstractLoggingBean, org.apache.sshd.sftp.client.SftpClient, .SftpClient.DirEntry, .SftpClient.Handle, .SftpClientHolder

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.

Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
private final SftpClient
private final boolean
private List<SftpClient.DirEntry>
private SftpClient.Handle
private final String
private final AtomicReference<Boolean>
private int
private final AtomicBoolean
Inherited from org.apache.sshd.common.util.logging.AbstractLoggingBean:
log

Constructor Summary

AccessConstructor and Description
public
SftpDirEntryIterator(SftpClient
The SftpClient instance to use for the iteration
client
,
String
The remote directory path
path
)

public
SftpDirEntryIterator(SftpClient
The SftpClient instance to use for the iteration
client
,
SftpClient.Handle
The directory Handle to use for listing the entries
dirHandle
)

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

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.nio.channels.Channel.close.

Closes this channel.

public final SftpClient
public final SftpClient.Handle

Returns:

The directory Handle used to access the remote directory
getHandle
()

public final String

Returns:

Remote directory hint - may be the handle's value if accessed directly via a Handle instead of via a path - used only for logging
getPath
()

The remotely accessed directory path

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public boolean
public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

protected List<SftpClient.DirEntry>
public SftpClient.DirEntry
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from org.apache.sshd.common.util.logging.AbstractLoggingBean:
debugdebugdebugdebugdebugerrorerrorerrorerrorerrorgetSimplifiedLoggerinfoinfowarnwarnwarnwarnwarnwarnwarnwarn

Field Detail

clientback to summary
private final SftpClient client
closeOnFinishedback to summary
private final boolean closeOnFinished
dirEntriesback to summary
private List<SftpClient.DirEntry> dirEntries
dirHandleback to summary
private SftpClient.Handle dirHandle
dirPathback to summary
private final String dirPath
eolIndicatorback to summary
private final AtomicReference<Boolean> eolIndicator
indexback to summary
private int index
openback to summary
private final AtomicBoolean open

Constructor Detail

SftpDirEntryIteratorback to summary
public SftpDirEntryIterator(SftpClient client, String path) throws IOException
Parameters
client:SftpClient

The SftpClient instance to use for the iteration

path:String

The remote directory path

Exceptions
IOException:
If failed to gain access to the remote directory path
SftpDirEntryIteratorback to summary
public SftpDirEntryIterator(SftpClient client, SftpClient.Handle dirHandle)
Parameters
client:SftpClient

The SftpClient instance to use for the iteration

dirHandle:SftpClient.Handle

The directory Handle to use for listing the entries

SftpDirEntryIteratorback to summary
public SftpDirEntryIterator(SftpClient client, String path, SftpClient.Handle dirHandle, boolean closeOnFinished)
Parameters
client:SftpClient

The SftpClient instance to use for the iteration

path:String

A hint as to the remote directory path - used only for logging

dirHandle:SftpClient.Handle

The directory Handle to use for listing the entries

closeOnFinished:boolean

If true then close the directory handle when all entries have been exhausted

Method Detail

closeback to summary
public void close() throws IOException

Implements java.nio.channels.Channel.close.

Doc from java.nio.channels.Channel.close.

Closes this channel.

After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.

If this channel is already closed then invoking this method has no effect.

This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
getClientback to summary
public final SftpClient getClient()

Implements org.apache.sshd.sftp.client.SftpClientHolder.getClient.

Annotations
@Override
getHandleback to summary
public final SftpClient.Handle getHandle()
Returns:SftpClient.Handle

The directory Handle used to access the remote directory

getPathback to summary
public final String getPath()

The remotely accessed directory path

Returns:String

Remote directory hint - may be the handle's value if accessed directly via a Handle instead of via a path - used only for logging

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
isCloseOnFinishedback to summary
public boolean isCloseOnFinished()
isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Returns:boolean

true if, and only if, this channel is open

Annotations
@Override
loadback to summary
protected List<SftpClient.DirEntry> load(SftpClient.Handle handle)
nextback to summary
public SftpClient.DirEntry next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:SftpClient.DirEntry

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override