Package org.terracotta.utilities.io
Class Files.CopyingFileVisitor
- java.lang.Object
-
- java.nio.file.SimpleFileVisitor<java.nio.file.Path>
-
- org.terracotta.utilities.io.Files.CopyingFileVisitor
-
- All Implemented Interfaces:
java.nio.file.FileVisitor<java.nio.file.Path>
- Enclosing class:
- Files
private static class Files.CopyingFileVisitor extends java.nio.file.SimpleFileVisitor<java.nio.file.Path>AFileVisitorimplementation that copies a directory tree.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.nio.file.CopyOption>copyOptionsprivate booleandeepCopyprivate java.nio.file.CopyOption[]effectiveCopyOptionsprivate java.nio.file.LinkOption[]linkOptionsprivate booleannoSpanprivate java.nio.file.Pathsourceprivate java.nio.file.FileStoresourceFileStoreprivate java.nio.file.Pathtarget
-
Constructor Summary
Constructors Constructor Description CopyingFileVisitor(java.nio.file.Path source, java.nio.file.Path target, java.util.Set<java.nio.file.CopyOption> copyOptions, java.nio.file.LinkOption[] linkOptions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckFileStore(java.nio.file.Path path, java.nio.file.LinkOption... linkOptions)Throws aFiles.FileStoreConstraintExceptionif the path provided, with links resolved according tolinkOptions, is not in the sameFileStoreas the specified copy source.private java.util.Optional<java.nio.file.Path>containedBy(java.nio.file.Path tree, java.nio.file.Path candidate)Determines if a path is contained in the tree rooted by another.java.nio.file.FileVisitResultpreVisitDirectory(java.nio.file.Path dir, java.nio.file.attribute.BasicFileAttributes attrs)Create the target directories usingFiles.copy(Path, Path, CopyOption...)to in order to copy the directory attributes if requested.private java.nio.file.Pathrelocate(java.nio.file.Path path)Make the source path provided refer to the same place in the target.java.nio.file.FileVisitResultvisitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attrs)Copy the source file usingFiles.copy(Path, Path, CopyOption...)to the like location in the target copying attributes as requested.
-
-
-
Field Detail
-
sourceFileStore
private final java.nio.file.FileStore sourceFileStore
-
target
private final java.nio.file.Path target
-
copyOptions
private final java.util.Set<java.nio.file.CopyOption> copyOptions
-
linkOptions
private final java.nio.file.LinkOption[] linkOptions
-
source
private final java.nio.file.Path source
-
noSpan
private final boolean noSpan
-
deepCopy
private final boolean deepCopy
-
effectiveCopyOptions
private final java.nio.file.CopyOption[] effectiveCopyOptions
-
-
Method Detail
-
relocate
private java.nio.file.Path relocate(java.nio.file.Path path)
Make the source path provided refer to the same place in the target.- Parameters:
path- the source path to relativize/resolve- Returns:
- the resolved target path
-
checkFileStore
private void checkFileStore(java.nio.file.Path path, java.nio.file.LinkOption... linkOptions) throws java.io.IOExceptionThrows aFiles.FileStoreConstraintExceptionif the path provided, with links resolved according tolinkOptions, is not in the sameFileStoreas the specified copy source.- Parameters:
path- thePathfor which theFileStoreis to be determinedlinkOptions-LinkOptionvalues used for interpretingpath- Throws:
java.io.IOException- if an error is raised in determining theFileStore
-
containedBy
private java.util.Optional<java.nio.file.Path> containedBy(java.nio.file.Path tree, java.nio.file.Path candidate)Determines if a path is contained in the tree rooted by another. This method is used instead ofPath.startsWith(Path)to properly handle differences observed under Windows with short- versus long-names under Windows.Both the
treeandcandidatepaths must be non-relative- Parameters:
tree- the root of the tree in whichcandidateis tested for residencecandidate- the candidatePathto test- Returns:
- an
Optionalcontaining the relative path betweentreeandcandidateiffcandidateis withintree; otherwise anOptional.empty()
-
preVisitDirectory
public java.nio.file.FileVisitResult preVisitDirectory(java.nio.file.Path dir, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOExceptionCreate the target directories usingFiles.copy(Path, Path, CopyOption...)to in order to copy the directory attributes if requested.- Specified by:
preVisitDirectoryin interfacejava.nio.file.FileVisitor<java.nio.file.Path>- Overrides:
preVisitDirectoryin classjava.nio.file.SimpleFileVisitor<java.nio.file.Path>- Parameters:
dir- the source directory to copyattrs- the attributes of the source directory- Returns:
FileVisitResult.CONTINUE- Throws:
java.io.IOException- if the copy fails
-
visitFile
public java.nio.file.FileVisitResult visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOExceptionCopy the source file usingFiles.copy(Path, Path, CopyOption...)to the like location in the target copying attributes as requested. Links presented here are either replicated -- if the link target is within the source tree -- or copied -- if the link target resides outside of the source tree.- Specified by:
visitFilein interfacejava.nio.file.FileVisitor<java.nio.file.Path>- Overrides:
visitFilein classjava.nio.file.SimpleFileVisitor<java.nio.file.Path>- Parameters:
file- the source file/link to copyattrs- the attributes of the source file- Returns:
FileVisitResult.CONTINUE- Throws:
java.io.IOException- if the copy fails
-
-