Package org.terracotta.utilities.io
Class FilesSupport
java.lang.Object
org.terracotta.utilities.io.FilesSupport
Support methods for the
Files implementation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classSupport class to open or lock a file for file operation impact assessment. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanprivate static final org.slf4j.Loggerprivate static final Pattern -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDynamically determine reasons for file operation retry.calculateReasons(Path top) Testing seam.Identifies theFileSystemException.getReason()messages for which file operations that warrant a retry.If a Windows platform, gets the current SUBST assignments, if any.pathType(BasicFileAttributes attributes) Determine the path type fromBasicFileAttributes.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
IS_WINDOWS
private static final boolean IS_WINDOWS -
SUBST_PAIR
-
-
Constructor Details
-
FilesSupport
FilesSupport()
-
-
Method Details
-
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
Determine the path type fromBasicFileAttributes.- Parameters:
attributes- theBasicFileAttributesto interpret- Returns:
- the list of path types; empty if the type cannot be determined
-
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
Dynamically determine reasons for file operation retry.- Returns:
- a
SetofFileSystemException.getReason()values warranting retry
-
calculateReasons
Testing seam.- Throws:
IOException- See Also:
-