Class 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

    public class SftpPathImpl
    extends SftpPath
    An SftpPath that can cache SftpClient.Attributes.
    • 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)
        SftpPath instances can cache SFTP SftpClient.Attributes. Caching can be enabled by passing true. If the SftpPath instance is already caching attributes, a counter is increased only. To disable caching, pass false, 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 to cacheAttributes(false). Such call pairs can be nested; caching is enabled for the duration of the outermost such pair. The outermost call passing true 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:
        withAttributeCache(Path, IOFunction)
      • cacheAttributes

        public void cacheAttributes​(SftpClient.Attributes attributes)
        Sets the cached attributes to the argument if this SftpPath instance is currently caching attributes. Otherwise a no-op.
        Parameters:
        attributes - the SftpClient.Attributes to cache
      • setAttributes

        public void setAttributes​(SftpClient.Attributes attributes)
        Unconditionally set the cached attributes, whether or not this instance's attribute cache is enabled.
        Parameters:
        attributes - the SftpClient.Attributes to cache
      • withAttributeCache

        public <T> T withAttributeCache​(IOFunction<java.nio.file.Path,​T> operation)
                                 throws java.io.IOException
        Performs the given operation with attribute caching. If SftpClient.Attributes are fetched by the operation, they will be cached and subsequently these cached attributes will be re-used for this SftpPath instance throughout the operation. Calls to withAttributeCache(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 the operation
        Parameters:
        operation - to perform; may return null if it has no result
        Returns:
        the result of the operation
        Throws:
        java.io.IOException - if thrown by the operation
      • withAttributeCache

        public static <T> T withAttributeCache​(java.nio.file.Path path,
                                               IOFunction<java.nio.file.Path,​T> operation)
                                        throws java.io.IOException
        Performs the given operation with attribute caching, if the given Path can cache attributes, otherwise simply executes the operation.
        Type Parameters:
        T - result type of the operation
        Parameters:
        path - Path to operate on
        operation - to perform; may return null if it has no result
        Returns:
        the result of the operation
        Throws:
        java.io.IOException - if thrown by the operation
        See Also:
        withAttributeCache(IOFunction)