Class FilesSupport

java.lang.Object
org.terracotta.utilities.io.FilesSupport

class FilesSupport extends Object
Support methods for the Files implementation.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • IS_WINDOWS

      private static final boolean IS_WINDOWS
    • SUBST_PAIR

      private static final Pattern SUBST_PAIR
  • Constructor Details

    • FilesSupport

      FilesSupport()
  • Method Details

    • getRetryReasons

      static Set<String> getRetryReasons()
      Identifies the FileSystemException.getReason() messages for which file operations that warrant a retry.

      For example, a likely cause for an AccessDeniedException from a Files.move(java.nio.file.Path, java.nio.file.Path, java.nio.file.CopyOption...), under Windows anyway, is that some other system process, like indexing or anti-virus, has the file momentarily open. A retry of a rename (or delete) is appropriate. Failures reflected by other FileSystemException instances can also warrant retry.

      Ideally, the JDK would reflect such "errors of interference" as specific exceptions that can be easily determined and a retry attempted. Unfortunately, the JDK can manifest this interference in many ways:

      1. AccessDeniedException reflects a Windows errorCode of 0x05 (ERROR_ACCESS_DENIED) or Unix error code of EACCES. This error could be persistent or temporary.
      2. FileSystemException with a _reason_ reflecting an error code like:
        • Windows ERROR_SHARING_VIOLATION (0x20)
        • Windows ERROR_LOCK_VIOLATION (0x21)
        • Unix EAGAIN
      Compounding the programmatic handling of these errors, a FileSystemException does not include the errorCode -- the reason text is obtained from the Windows FormatMessageW function specifying 0x0 as the 'dwLanguageId' parameter or the Unix strerror function. This means that the reason text is, potentially, in the local language and not suitable for reliable parsing.
      Returns:
      the set of reason messages determined to be retryable
    • pathType

      static List<String> pathType(BasicFileAttributes attributes)
      Determine the path type from BasicFileAttributes.
      Parameters:
      attributes - the BasicFileAttributes to interpret
      Returns:
      the list of path types; empty if the type cannot be determined
    • getSubsts

      static Map<Path,Path> getSubsts()
      If a Windows platform, gets the current SUBST assignments, if any. Because the SUBST list can change without notice, this assignment map is not cached. A failure in obtaining the assignment list results in the return of an empty map.
      Returns:
      the current SUBST assignments
    • calculateReasons

      private static Set<String> calculateReasons()
      Dynamically determine reasons for file operation retry.
      Returns:
      a Set of FileSystemException.getReason() values warranting retry
    • calculateReasons

      static Set<String> calculateReasons(Path top) throws IOException
      Testing seam.
      Throws:
      IOException
      See Also: