Package org.apache.commons.io.file
Class CopyDirectoryVisitor
- java.lang.Object
-
- java.nio.file.SimpleFileVisitor<java.nio.file.Path>
-
- org.apache.commons.io.file.SimplePathVisitor
-
- org.apache.commons.io.file.CountingPathVisitor
-
- org.apache.commons.io.file.CopyDirectoryVisitor
-
- All Implemented Interfaces:
java.nio.file.FileVisitor<java.nio.file.Path>,PathVisitor
public class CopyDirectoryVisitor extends CountingPathVisitor
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
Fields Modifier and Type Field Description private java.nio.file.CopyOption[]copyOptionsprivate java.nio.file.PathsourceDirectoryprivate java.nio.file.PathtargetDirectory-
Fields inherited from class org.apache.commons.io.file.CountingPathVisitor
EMPTY_STRING_ARRAY
-
-
Constructor Summary
Constructors Constructor Description CopyDirectoryVisitor(Counters.PathCounters pathCounter, java.nio.file.Path sourceDirectory, java.nio.file.Path targetDirectory, java.nio.file.CopyOption... copyOptions)Constructs a instance that deletes files except for the files and directories explicitly given.CopyDirectoryVisitor(Counters.PathCounters pathCounter, PathFilter fileFilter, PathFilter dirFilter, java.nio.file.Path sourceDirectory, java.nio.file.Path targetDirectory, java.nio.file.CopyOption... copyOptions)Constructs a instance that deletes files except for the files and directories explicitly given.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcopy(java.nio.file.Path sourceFile, java.nio.file.Path targetFile)Copies the sourceFile to the targetFile.booleanequals(java.lang.Object obj)java.nio.file.CopyOption[]getCopyOptions()Gets the copy options.java.nio.file.PathgetSourceDirectory()Gets the source directory.java.nio.file.PathgetTargetDirectory()Gets the target directory.inthashCode()java.nio.file.FileVisitResultpreVisitDirectory(java.nio.file.Path directory, java.nio.file.attribute.BasicFileAttributes attributes)private java.nio.file.PathresolveRelativeAsString(java.nio.file.Path directory)Relativizes againstsourceDirectory, then resolves againsttargetDirectory.private static java.nio.file.CopyOption[]toCopyOption(java.nio.file.CopyOption... copyOptions)java.nio.file.FileVisitResultvisitFile(java.nio.file.Path sourceFile, java.nio.file.attribute.BasicFileAttributes attributes)-
Methods inherited from class org.apache.commons.io.file.CountingPathVisitor
defaultDirectoryFilter, defaultDirectoryTransformer, defaultFileFilter, defaultPathCounters, getPathCounters, postVisitDirectory, toString, updateDirCounter, updateFileCounters, withBigIntegerCounters, withLongCounters
-
Methods inherited from class org.apache.commons.io.file.SimplePathVisitor
visitFileFailed
-
-
-
-
Constructor Detail
-
CopyDirectoryVisitor
public CopyDirectoryVisitor(Counters.PathCounters pathCounter, java.nio.file.Path sourceDirectory, java.nio.file.Path targetDirectory, java.nio.file.CopyOption... copyOptions)
Constructs a instance that deletes files except for the files and directories explicitly given.- 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, java.nio.file.Path sourceDirectory, java.nio.file.Path targetDirectory, java.nio.file.CopyOption... copyOptions)
Constructs a instance that deletes files except for the files and directories explicitly given.- 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 Detail
-
toCopyOption
private static java.nio.file.CopyOption[] toCopyOption(java.nio.file.CopyOption... copyOptions)
-
copy
protected void copy(java.nio.file.Path sourceFile, java.nio.file.Path targetFile) throws java.io.IOExceptionCopies the sourceFile to the targetFile.- Parameters:
sourceFile- the source file.targetFile- the target file.- Throws:
java.io.IOException- if an I/O error occurs.- Since:
- 2.8.0
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classCountingPathVisitor
-
getCopyOptions
public java.nio.file.CopyOption[] getCopyOptions()
Gets the copy options.- Returns:
- the copy options.
- Since:
- 2.8.0
-
getSourceDirectory
public java.nio.file.Path getSourceDirectory()
Gets the source directory.- Returns:
- the source directory.
- Since:
- 2.8.0
-
getTargetDirectory
public java.nio.file.Path getTargetDirectory()
Gets the target directory.- Returns:
- the target directory.
- Since:
- 2.8.0
-
hashCode
public int hashCode()
- Overrides:
hashCodein classCountingPathVisitor
-
preVisitDirectory
public java.nio.file.FileVisitResult preVisitDirectory(java.nio.file.Path directory, java.nio.file.attribute.BasicFileAttributes attributes) throws java.io.IOException- Specified by:
preVisitDirectoryin interfacejava.nio.file.FileVisitor<java.nio.file.Path>- Overrides:
preVisitDirectoryin classCountingPathVisitor- Throws:
java.io.IOException
-
resolveRelativeAsString
private java.nio.file.Path resolveRelativeAsString(java.nio.file.Path directory)
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 java.nio.file.FileVisitResult visitFile(java.nio.file.Path sourceFile, java.nio.file.attribute.BasicFileAttributes attributes) throws java.io.IOException- Specified by:
visitFilein interfacejava.nio.file.FileVisitor<java.nio.file.Path>- Overrides:
visitFilein classCountingPathVisitor- Throws:
java.io.IOException
-
-