Class SftpPathImpl

All Implemented Interfaces:
Comparable<Path>, Iterable<Path>, Path, Watchable

public class SftpPathImpl extends SftpPath
An SftpPath that can cache SftpClient.Attributes.
  • Field Details

  • Constructor Details

  • Method Details

    • 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:
    • 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
    • getAttributes

      public SftpClient.Attributes getAttributes()
      Description copied from class: SftpPath
      Retrieves the cached SftpClient.Attributes of this SftpPath, if it has any.
      Overrides:
      getAttributes in class SftpPath
      Returns:
      the cached SftpClient.Attributes or null if there are none cached
    • withAttributeCache

      public <T> T withAttributeCache(IOFunction<Path,T> operation) throws 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:
      IOException - if thrown by the operation
    • withAttributeCache

      public static <T> T withAttributeCache(Path path, IOFunction<Path,T> operation) throws 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:
      IOException - if thrown by the operation
      See Also: