Package org.apache.commons.io.file
Class CopyDirectoryVisitor
java.lang.Object
java.nio.file.SimpleFileVisitor<Path>
org.apache.commons.io.file.SimplePathVisitor
org.apache.commons.io.file.CountingPathVisitor
org.apache.commons.io.file.CopyDirectoryVisitor
- All Implemented Interfaces:
FileVisitor<Path>,PathVisitor
Copies a source directory to a target directory.
- Since:
- 2.7
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.io.file.CountingPathVisitor
CountingPathVisitor.AbstractBuilder<T,B extends CountingPathVisitor.AbstractBuilder<T, B>>, CountingPathVisitor.Builder -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CopyOption[]private final Pathprivate final PathFields inherited from class org.apache.commons.io.file.CountingPathVisitor
EMPTY_STRING_ARRAY -
Constructor Summary
ConstructorsConstructorDescriptionCopyDirectoryVisitor(Counters.PathCounters pathCounter, Path sourceDirectory, Path targetDirectory, CopyOption... copyOptions) Constructs an instance that copies all files.CopyDirectoryVisitor(Counters.PathCounters pathCounter, PathFilter fileFilter, PathFilter dirFilter, Path sourceDirectory, Path targetDirectory, CopyOption... copyOptions) Constructs an instance that copies files matching the given file and directory filters. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCopies the sourceFile to the targetFile.booleanGets the copy options.Gets the source directory.Gets the target directory.inthashCode()preVisitDirectory(Path directory, BasicFileAttributes attributes) private PathresolveRelativeAsString(Path directory) Relativizes againstsourceDirectory, then resolves againsttargetDirectory.private static CopyOption[]toCopyOption(CopyOption... copyOptions) visitFile(Path sourceFile, BasicFileAttributes attributes) Methods inherited from class org.apache.commons.io.file.CountingPathVisitor
accept, defaultDirectoryFilter, defaultDirectoryTransformer, defaultFileFilter, defaultPathCounters, getPathCounters, postVisitDirectory, toString, updateDirCounter, updateFileCounters, withBigIntegerCounters, withLongCountersMethods inherited from class org.apache.commons.io.file.SimplePathVisitor
visitFileFailed
-
Field Details
-
copyOptions
-
sourceDirectory
-
targetDirectory
-
-
Constructor Details
-
CopyDirectoryVisitor
public CopyDirectoryVisitor(Counters.PathCounters pathCounter, Path sourceDirectory, Path targetDirectory, CopyOption... copyOptions) Constructs an instance that copies all files.- Parameters:
pathCounter- How to count visits.sourceDirectory- The source directorytargetDirectory- The target directorycopyOptions- Specifies how the copying should be done.
-
CopyDirectoryVisitor
public CopyDirectoryVisitor(Counters.PathCounters pathCounter, PathFilter fileFilter, PathFilter dirFilter, Path sourceDirectory, Path targetDirectory, CopyOption... copyOptions) Constructs an instance that copies files matching the given file and directory filters.- Parameters:
pathCounter- How to count visits.fileFilter- How to filter file paths.dirFilter- How to filter directory paths.sourceDirectory- The source directorytargetDirectory- The target directorycopyOptions- Specifies how the copying should be done.- Since:
- 2.9.0
-
-
Method Details
-
toCopyOption
-
copy
Copies the sourceFile to the targetFile.- Parameters:
sourceFile- the source file.targetFile- the target file.- Throws:
IOException- if an I/O error occurs.- Since:
- 2.8.0
-
equals
- Overrides:
equalsin classCountingPathVisitor
-
getCopyOptions
Gets the copy options.- Returns:
- the copy options.
- Since:
- 2.8.0
-
getSourceDirectory
Gets the source directory.- Returns:
- the source directory.
- Since:
- 2.8.0
-
getTargetDirectory
Gets the target directory.- Returns:
- the target directory.
- Since:
- 2.8.0
-
hashCode
public int hashCode()- Overrides:
hashCodein classCountingPathVisitor
-
preVisitDirectory
public FileVisitResult preVisitDirectory(Path directory, BasicFileAttributes attributes) throws IOException - Specified by:
preVisitDirectoryin interfaceFileVisitor<Path>- Overrides:
preVisitDirectoryin classCountingPathVisitor- Throws:
IOException
-
resolveRelativeAsString
Relativizes againstsourceDirectory, then resolves againsttargetDirectory.We call
Path.toString()on the relativized value because we cannot use paths from different FileSystems which throwsProviderMismatchException. Special care is taken to handle differences in file system separators.- Parameters:
directory- the directory to relativize.- Returns:
- a new path, relativized against sourceDirectory, then resolved against targetDirectory.
-
visitFile
public FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attributes) throws IOException - Specified by:
visitFilein interfaceFileVisitor<Path>- Overrides:
visitFilein classCountingPathVisitor- Throws:
IOException
-