Package org.terracotta.utilities.io
Class Files.CopyingFileVisitor
- All Implemented Interfaces:
FileVisitor<Path>
- Enclosing class:
- Files
A
FileVisitor implementation that copies a directory tree.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Set<CopyOption>private final booleanprivate final CopyOption[]private final LinkOption[]private final booleanprivate final Pathprivate final FileStoreprivate final Path -
Constructor Summary
ConstructorsConstructorDescriptionCopyingFileVisitor(Path source, Path target, Set<CopyOption> copyOptions, LinkOption[] linkOptions) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckFileStore(Path path, LinkOption... linkOptions) Throws aFiles.FileStoreConstraintExceptionif the path provided, with links resolved according tolinkOptions, is not in the sameFileStoreas the specified copy source.containedBy(Path tree, Path candidate) Determines if a path is contained in the tree rooted by another.preVisitDirectory(Path dir, BasicFileAttributes attrs) Create the target directories usingFiles.copy(Path, Path, CopyOption...)to in order to copy the directory attributes if requested.private PathMake the source path provided refer to the same place in the target.visitFile(Path file, BasicFileAttributes attrs) Copy the source file usingFiles.copy(Path, Path, CopyOption...)to the like location in the target copying attributes as requested.Methods inherited from class java.nio.file.SimpleFileVisitor
postVisitDirectory, visitFileFailed
-
Field Details
-
sourceFileStore
-
target
-
copyOptions
-
linkOptions
-
source
-
noSpan
private final boolean noSpan -
deepCopy
private final boolean deepCopy -
effectiveCopyOptions
-
-
Constructor Details
-
CopyingFileVisitor
public CopyingFileVisitor(Path source, Path target, Set<CopyOption> copyOptions, LinkOption[] linkOptions) throws IOException - Throws:
IOException
-
-
Method Details
-
relocate
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
Throws 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:
IOException- if an error is raised in determining theFileStore
-
containedBy
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
Create the target directories usingFiles.copy(Path, Path, CopyOption...)to in order to copy the directory attributes if requested.- Specified by:
preVisitDirectoryin interfaceFileVisitor<Path>- Overrides:
preVisitDirectoryin classSimpleFileVisitor<Path>- Parameters:
dir- the source directory to copyattrs- the attributes of the source directory- Returns:
FileVisitResult.CONTINUE- Throws:
IOException- if the copy fails
-
visitFile
Copy 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 interfaceFileVisitor<Path>- Overrides:
visitFilein classSimpleFileVisitor<Path>- Parameters:
file- the source file/link to copyattrs- the attributes of the source file- Returns:
FileVisitResult.CONTINUE- Throws:
IOException- if the copy fails
-