Package org.apache.sshd.sftp.client.impl
Class SftpPathImpl
java.lang.Object
org.apache.sshd.common.file.util.BasePath<SftpPath,SftpFileSystem>
org.apache.sshd.sftp.client.fs.SftpPath
org.apache.sshd.sftp.client.impl.SftpPathImpl
An
SftpPath
that can cache SftpClient.Attributes
.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
cacheAttributes
(boolean doCache) SftpPath
instances can cache SFTPSftpClient.Attributes
.void
cacheAttributes
(SftpClient.Attributes attributes) Sets the cached attributes to the argument if thisSftpPath
instance is currently caching attributes.Retrieves the cachedSftpClient.Attributes
of thisSftpPath
, if it has any.void
setAttributes
(SftpClient.Attributes attributes) Unconditionally set the cached attributes, whether or not this instance's attribute cache is enabled.static <T> T
withAttributeCache
(Path path, IOFunction<Path, T> operation) Performs the given operation with attribute caching, if the givenPath
can cache attributes, otherwise simply executes the operation.<T> T
withAttributeCache
(IOFunction<Path, T> operation) Performs the given operation with attribute caching.Methods inherited from class org.apache.sshd.sftp.client.fs.SftpPath
toRealPath
Methods inherited from class org.apache.sshd.common.file.util.BasePath
asString, asT, calculatedHashCode, checkPath, compare, compareTo, create, create, create, endsWith, endsWith, endsWith, equals, getFileName, getFileSystem, getName, getNameCount, getParent, getRoot, hashCode, isAbsolute, isNormal, iterator, normalize, register, register, relativize, resolve, resolve, resolveSibling, resolveSibling, startsWith, startsWith, startsWith, subpath, toAbsolutePath, toFile, toString, toUri
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
attributes
-
cachingLevel
private int cachingLevel
-
-
Constructor Details
-
SftpPathImpl
-
-
Method Details
-
cacheAttributes
protected void cacheAttributes(boolean doCache) SftpPath
instances can cache SFTPSftpClient.Attributes
. Caching can be enabled by passingtrue
. If theSftpPath
instance is already caching attributes, a counter is increased only. To disable caching, passfalse
, which decreases the counter. The cache is cleared when the counter reaches zero again.Each call of
cacheAttributes(true)
must be matched by a call tocacheAttributes(false)
. Such call pairs can be nested; caching is enabled for the duration of the outermost such pair. The outermost call passingtrue
clears any possibly already cached attributes so that the next attempt to read remote attributes will fetch them anew.Client code should use
withAttributeCache(Path, IOFunction)
, which ensures the above condition.- Parameters:
doCache
- whether to start caching (increasing the cache level) or to stop caching (decreasing the cache level)- See Also:
-
cacheAttributes
Sets the cached attributes to the argument if thisSftpPath
instance is currently caching attributes. Otherwise a no-op.- Parameters:
attributes
- theSftpClient.Attributes
to cache
-
setAttributes
Unconditionally set the cached attributes, whether or not this instance's attribute cache is enabled.- Parameters:
attributes
- theSftpClient.Attributes
to cache
-
getAttributes
Description copied from class:SftpPath
Retrieves the cachedSftpClient.Attributes
of thisSftpPath
, if it has any.- Overrides:
getAttributes
in classSftpPath
- Returns:
- the cached
SftpClient.Attributes
ornull
if there are none cached
-
withAttributeCache
Performs the given operation with attribute caching. IfSftpClient.Attributes
are fetched by the operation, they will be cached and subsequently these cached attributes will be re-used for thisSftpPath
instance throughout the operation. Calls towithAttributeCache(IOFunction)
may be nested. The cache is cleared at the start and at the end of the outermost invocation.- Type Parameters:
T
- result type of theoperation
- Parameters:
operation
- to perform; may returnnull
if it has no result- Returns:
- the result of the
operation
- Throws:
IOException
- if thrown by theoperation
-
withAttributeCache
Performs the given operation with attribute caching, if the givenPath
can cache attributes, otherwise simply executes the operation.- Type Parameters:
T
- result type of theoperation
- Parameters:
path
-Path
to operate onoperation
- to perform; may returnnull
if it has no result- Returns:
- the result of the
operation
- Throws:
IOException
- if thrown by theoperation
- See Also:
-