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
-
- All Implemented Interfaces:
java.lang.Comparable<java.nio.file.Path>,java.lang.Iterable<java.nio.file.Path>,java.nio.file.Path,java.nio.file.Watchable,WithFileAttributeCache,WithFileAttributes
public class SftpPathImpl extends SftpPath implements WithFileAttributeCache
AnSftpPaththat can cacheSftpClient.Attributes.
-
-
Field Summary
Fields Modifier and Type Field Description private SftpClient.Attributesattributesprivate intcachingLevel
-
Constructor Summary
Constructors Constructor Description SftpPathImpl(SftpFileSystem fileSystem, java.lang.String root, java.util.List<java.lang.String> names)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcacheAttributes(boolean doCache)SftpPathinstances can cache SFTPSftpClient.Attributes.SftpClient.AttributesgetAttributes()Retrieves theSftpClient.Attributesof this object, if it has any.voidsetAttributes(SftpClient.Attributes attributes)Sets the attributes.<T> TwithAttributeCache(IOFunction<java.nio.file.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
-
-
-
-
Field Detail
-
attributes
private SftpClient.Attributes attributes
-
cachingLevel
private int cachingLevel
-
-
Constructor Detail
-
SftpPathImpl
public SftpPathImpl(SftpFileSystem fileSystem, java.lang.String root, java.util.List<java.lang.String> names)
-
-
Method Detail
-
cacheAttributes
protected void cacheAttributes(boolean doCache)
SftpPathinstances can cache SFTPSftpClient.Attributes. Caching can be enabled by passingtrue. If theSftpPathinstance 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 passingtrueclears any possibly already cached attributes so that the next attempt to read remote attributes will fetch them anew.Client code should use
WithFileAttributeCache.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:
WithFileAttributeCache.withAttributeCache(Path, IOFunction)
-
setAttributes
public void setAttributes(SftpClient.Attributes attributes)
Description copied from interface:WithFileAttributeCacheSets the attributes.- Specified by:
setAttributesin interfaceWithFileAttributeCache- Parameters:
attributes-SftpClient.Attributesto set
-
getAttributes
public SftpClient.Attributes getAttributes()
Description copied from interface:WithFileAttributesRetrieves theSftpClient.Attributesof this object, if it has any.- Specified by:
getAttributesin interfaceWithFileAttributes- Overrides:
getAttributesin classSftpPath- Returns:
- the
SftpClient.Attributesornullif there are none
-
withAttributeCache
public <T> T withAttributeCache(IOFunction<java.nio.file.Path,T> operation) throws java.io.IOException
Description copied from interface:WithFileAttributeCachePerforms the given operation with attribute caching. IfSftpClient.Attributesare fetched by the operation, they will be cached and subsequently these cached attributes will be re-used for thisSftpPathinstance throughout the operation. Calls toWithFileAttributeCache.withAttributeCache(IOFunction)may be nested. The cache is cleared at the start and at the end of the outermost invocation.- Specified by:
withAttributeCachein interfaceWithFileAttributeCache- Type Parameters:
T- result type of theoperation- Parameters:
operation- to perform; may returnnullif it has no result- Returns:
- the result of the
operation - Throws:
java.io.IOException- if thrown by theoperation
-
-