public class FileCopyTask extends Object
This implementation is based on Arnout Kuiper's initial design document, the following mailing list discussions, and the copyfile/copydir tasks.
| Modifier and Type | Field and Description |
|---|---|
protected Hashtable<File,File> |
completeDirMap |
protected File |
destDir |
protected File |
destFile |
protected Hashtable<String,String[]> |
dirCopyMap |
protected boolean |
failonerror |
protected File |
file |
protected Hashtable<String,String[]> |
fileCopyMap |
protected Vector<FileSet> |
filesets |
protected boolean |
flatten |
protected boolean |
forceOverwrite |
protected boolean |
includeEmpty |
protected Mapper |
mapperElement |
protected boolean |
preserveLastModified |
| Constructor and Description |
|---|
FileCopyTask()
Copy task constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(FileNameMapper fileNameMapper)
A nested filenamemapper
|
void |
addFileSet(FileSet set)
Adds a set of files to copy.
|
protected void |
buildMap(File fromDir,
File toDir,
String[] names,
FileNameMapper mapper,
Hashtable<String,String[]> map)
Add to a map of files/directories to copy
|
Mapper |
createMapper()
Defines the mapper to map source to destination files.
|
protected void |
doFileOperations()
Actually does the file (and possibly empty directory) copies.
|
void |
execute()
Performs the copy operation.
|
boolean |
getPreserveLastModified()
Whether to give the copied files the same last modified time as
the original files.
|
boolean |
isEnableMultipleMapping() |
protected void |
scan(File fromDir,
File toDir,
String[] files,
String[] dirs)
Compares source files to destination files to see if they should be
copied.
|
void |
setEnableMultipleMappings(boolean enableMultipleMappings)
Attribute to handle mappers that return multiple
mappings for a given source path.
|
void |
setFailOnError(boolean failonerror)
If false, note errors to the output but keep going.
|
void |
setFile(File file)
Sets a single source file to copy.
|
void |
setFlatten(boolean flatten)
When copying directory trees, the files can be "flattened"
into a single directory.
|
void |
setGranularity(long granularity)
The number of milliseconds leeway to give before deciding a
target is out of date.
|
void |
setIncludeEmptyDirs(boolean includeEmpty)
Used to copy empty directories.
|
void |
setOverwrite(boolean overwrite)
Overwrite any existing destination file(s).
|
void |
setPreserveLastModified(boolean preserve)
Give the copied files the same last modified time as the original files.
|
void |
setToDir(File destDir)
Sets the destination directory.
|
void |
setToFile(File destFile)
Sets the destination file.
|
protected void |
validateAttributes()
Ensure we have a consistent and legal set of attributes, and set
any internal flags necessary based on different combinations
of attributes.
|
protected File file
protected File destFile
protected File destDir
protected boolean preserveLastModified
protected boolean forceOverwrite
protected boolean flatten
protected boolean includeEmpty
protected boolean failonerror
protected Mapper mapperElement
public void setFile(File file)
file - the file to copypublic void setToFile(File destFile)
destFile - the file to copy topublic void setToDir(File destDir)
destDir - the destination directorypublic void setPreserveLastModified(boolean preserve)
preserve - if true perverse the modified time, default is falsepublic boolean getPreserveLastModified()
public void setOverwrite(boolean overwrite)
overwrite - if true force overwriting of destination file(s)
even if the destination file(s) are younger than
the corresponding source file. Default is false.public void setFlatten(boolean flatten)
flatten - if true flatten the destination directory. Default
is false.public void setIncludeEmptyDirs(boolean includeEmpty)
includeEmpty - if true copy empty directories. Default is true.public void setEnableMultipleMappings(boolean enableMultipleMappings)
enableMultipleMappings - If true the task will
copy to all the mappings for a given source path, if
false, only the first file or directory is
processed.
By default, this setting is false to provide backward
compatibility with earlier releases.public boolean isEnableMultipleMapping()
public void setFailOnError(boolean failonerror)
failonerror - true or falsepublic void addFileSet(FileSet set)
set - a set of files to copypublic Mapper createMapper() throws Exception
Exception - if more than one mapper is definedpublic void add(FileNameMapper fileNameMapper) throws Exception
fileNameMapper - the mapper to addExceptionpublic void setGranularity(long granularity)
Default is 0 milliseconds, or 2 seconds on DOS systems.
public void execute()
throws Exception
Exception - if an error occursprotected void validateAttributes()
throws Exception
Exception - if an error occursprotected void scan(File fromDir, File toDir, String[] files, String[] dirs) throws Exception
fromDir - The source directorytoDir - The destination directoryfiles - A list of files to copydirs - A list of directories to copyExceptionprotected void buildMap(File fromDir, File toDir, String[] names, FileNameMapper mapper, Hashtable<String,String[]> map) throws Exception
fromDir - the source directorytoDir - the destination directorynames - a list of filenamesmapper - a FileNameMapper valuemap - a map of source file to array of destination filesExceptionCopyright © 2001–2025. All rights reserved.