Package org.terracotta.utilities.io
Class FilesSupport
- java.lang.Object
-
- org.terracotta.utilities.io.FilesSupport
-
class FilesSupport extends java.lang.ObjectSupport methods for theFilesimplementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classFilesSupport.PathHolderSupport class to open or lock a file for file operation impact assessment.
-
Field Summary
Fields Modifier and Type Field Description private static booleanIS_WINDOWSprivate static org.slf4j.LoggerLOGGERprivate static java.util.regex.PatternSUBST_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 theFileSystemException.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 fromBasicFileAttributes.
-
-
-
Method Detail
-
getRetryReasons
static java.util.Set<java.lang.String> getRetryReasons()
Identifies theFileSystemException.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 otherFileSystemExceptioninstances 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:
AccessDeniedExceptionreflects a Windows errorCode of 0x05 (ERROR_ACCESS_DENIED) or Unix error code of EACCES. This error could be persistent or temporary.FileSystemExceptionwith a _reason_ reflecting an error code like:- Windows ERROR_SHARING_VIOLATION (0x20)
- Windows ERROR_LOCK_VIOLATION (0x21)
- Unix EAGAIN
FileSystemExceptiondoes not include the errorCode -- the reason text is obtained from the WindowsFormatMessageWfunction specifying 0x0 as the 'dwLanguageId' parameter or the Unixstrerrorfunction. 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 fromBasicFileAttributes.- Parameters:
attributes- theBasicFileAttributesto 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
SetofFileSystemException.getReason()values warranting retry
-
calculateReasons
static java.util.Set<java.lang.String> calculateReasons(java.nio.file.Path top) throws java.io.IOExceptionTesting seam.- Throws:
java.io.IOException- See Also:
calculateReasons()
-
-