Class FilesSupport


  • class FilesSupport
    extends java.lang.Object
    Support methods for the Files implementation.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  FilesSupport.PathHolder
      Support class to open or lock a file for file operation impact assessment.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static boolean IS_WINDOWS  
      private static org.slf4j.Logger LOGGER  
      private static java.util.regex.Pattern SUBST_PAIR  
    • Constructor Summary

      Constructors 
      Constructor Description
      FilesSupport()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.util.Set<java.lang.String> calculateReasons()
      Dynamically determine reasons for file operation retry.
      (package private) static java.util.Set<java.lang.String> calculateReasons​(java.nio.file.Path top)
      Testing seam.
      (package private) static java.util.Set<java.lang.String> getRetryReasons()
      Identifies the FileSystemException.getReason() messages for which file operations that warrant a retry.
      (package private) static java.util.Map<java.nio.file.Path,​java.nio.file.Path> getSubsts()
      If a Windows platform, gets the current SUBST assignments, if any.
      (package private) static java.util.List<java.lang.String> pathType​(java.nio.file.attribute.BasicFileAttributes attributes)
      Determine the path type from BasicFileAttributes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • IS_WINDOWS

        private static final boolean IS_WINDOWS
      • SUBST_PAIR

        private static final java.util.regex.Pattern SUBST_PAIR
    • Constructor Detail

      • FilesSupport

        FilesSupport()
    • Method Detail

      • getRetryReasons

        static java.util.Set<java.lang.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 java.util.List<java.lang.String> pathType​(java.nio.file.attribute.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 java.util.Map<java.nio.file.Path,​java.nio.file.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 java.util.Set<java.lang.String> calculateReasons()
        Dynamically determine reasons for file operation retry.
        Returns:
        a Set of FileSystemException.getReason() values warranting retry
      • calculateReasons

        static java.util.Set<java.lang.String> calculateReasons​(java.nio.file.Path top)
                                                         throws java.io.IOException
        Testing seam.
        Throws:
        java.io.IOException
        See Also:
        calculateReasons()