Class Files.CopyingFileVisitor

java.lang.Object
java.nio.file.SimpleFileVisitor<Path>
org.terracotta.utilities.io.Files.CopyingFileVisitor
All Implemented Interfaces:
FileVisitor<Path>
Enclosing class:
Files

private static class Files.CopyingFileVisitor extends SimpleFileVisitor<Path>
A FileVisitor implementation that copies a directory tree.
  • Field Details

    • sourceFileStore

      private final FileStore sourceFileStore
    • target

      private final Path target
    • copyOptions

      private final Set<CopyOption> copyOptions
    • linkOptions

      private final LinkOption[] linkOptions
    • source

      private final Path source
    • noSpan

      private final boolean noSpan
    • deepCopy

      private final boolean deepCopy
    • effectiveCopyOptions

      private final CopyOption[] effectiveCopyOptions
  • Constructor Details

  • Method Details

    • relocate

      private Path relocate(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(Path path, LinkOption... linkOptions) throws IOException
      Throws a Files.FileStoreConstraintException if the path provided, with links resolved according to linkOptions, is not in the same FileStore as the specified copy source.
      Parameters:
      path - the Path for which the FileStore is to be determined
      linkOptions - LinkOption values used for interpreting path
      Throws:
      IOException - if an error is raised in determining the FileStore
    • containedBy

      private Optional<Path> containedBy(Path tree, Path candidate)
      Determines if a path is contained in the tree rooted by another. This method is used instead of Path.startsWith(Path) to properly handle differences observed under Windows with short- versus long-names under Windows.

      Both the tree and candidate paths must be non-relative

      Parameters:
      tree - the root of the tree in which candidate is tested for residence
      candidate - the candidate Path to test
      Returns:
      an Optional containing the relative path between tree and candidate iff candidate is within tree; otherwise an Optional.empty()
    • preVisitDirectory

      public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException
      Create the target directories using Files.copy(Path, Path, CopyOption...) to in order to copy the directory attributes if requested.
      Specified by:
      preVisitDirectory in interface FileVisitor<Path>
      Overrides:
      preVisitDirectory in class SimpleFileVisitor<Path>
      Parameters:
      dir - the source directory to copy
      attrs - the attributes of the source directory
      Returns:
      FileVisitResult.CONTINUE
      Throws:
      IOException - if the copy fails
    • visitFile

      public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
      Copy the source file using Files.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:
      visitFile in interface FileVisitor<Path>
      Overrides:
      visitFile in class SimpleFileVisitor<Path>
      Parameters:
      file - the source file/link to copy
      attrs - the attributes of the source file
      Returns:
      FileVisitResult.CONTINUE
      Throws:
      IOException - if the copy fails