public class DefaultFileHandler extends LoggedObject implements FileHandler
FileHandler.XmlReplacement| Constructor and Description |
|---|
DefaultFileHandler()
Initializations.
|
| Modifier and Type | Method and Description |
|---|---|
String |
append(String path,
String suffixToAppend)
Append a suffix path to an existing path.
|
void |
copy(InputStream in,
OutputStream out)
Copies data from an InputStream to an OutputStream using a default buffer size.
|
void |
copy(InputStream in,
OutputStream out,
int bufSize)
Copies data from an InputStream to an OutputStream.
|
void |
copyDirectory(String source,
String target)
Copy a directory from a source to a destination.
|
void |
copyDirectory(String source,
String target,
org.apache.tools.ant.types.FilterChain filterChain,
String encoding)
Copy a directory from a source to a destination using a filterchain to specify token
replacement.
|
void |
copyDirectory(String source,
String target,
List<String> excludes)
Copy a directory from a source to a destination specifying files to be excluded.
|
void |
copyFile(String source,
String target)
Copy a file from a source to a destination.
|
void |
copyFile(String source,
String target,
boolean overwrite)
Copy a file from a source to a destination specifying if source files may overwrite newer
destination files.
|
void |
copyFile(String source,
String target,
org.apache.tools.ant.types.FilterChain filterChain) |
void |
copyFile(String source,
String target,
org.apache.tools.ant.types.FilterChain filterChain,
String encoding)
Copy a file from a source to a destination using a filterchain to specify token replacement.
|
String |
createDirectory(String parentDir,
String name)
Convenience method for creating a new directory inside another one.
|
void |
createFile(String file)
Create a file.
|
String |
createUniqueTmpDirectory()
Creates a unique temporary directory.
|
void |
delete(String path)
Deletes a file or directory, removing any children as appropriate.
|
boolean |
exists(String path) |
String |
getAbsolutePath(String path)
gets the absolute path from a file that may be relative to the current directory.
|
String[] |
getChildren(String directory) |
InputStream |
getInputStream(String file) |
String |
getName(String file) |
OutputStream |
getOutputStream(String file) |
String |
getParent(String path) |
long |
getSize(String file) |
String |
getTmpPath(String name)
Compute the location of a temporary directory.
|
String |
getURL(String path) |
boolean |
isDirectory(String path) |
boolean |
isDirectoryEmpty(String dir) |
void |
mkdirs(String path)
Create directories for the passed path.
|
String |
readTextFile(String file,
String encoding) |
void |
replaceInFile(String file,
Map<String,String> replacements,
String encoding)
Replaces using a map of replacements in a given file.
|
void |
replaceInFile(String file,
Map<String,String> replacements,
String encoding,
boolean ignoreNonExistingProperties)
Replaces using a map of replacements in a given file.
|
void |
replaceInXmlFile(String file,
Map<FileHandler.XmlReplacement,String> replacements)
Replaces using a map of XML replacements in a given file.
|
void |
replaceInXmlFile(String file,
Map<FileHandler.XmlReplacement,String> replacements,
boolean ignoreNonExistingProperties)
Replaces using a map of XML replacements in a given file.
|
void |
writeTextFile(String file,
String content,
String encoding) |
getLogger, setLoggerpublic void copyFile(String source, String target)
copyFile in interface FileHandlersource - the file to copy from. Must not be null.target - the file to copy to. Must not be null.FileHandler.copyFile(String, String)public void copyFile(String source, String target, boolean overwrite)
copyFile in interface FileHandlersource - the file to copy from. Must not be null.target - the file to copy to. Must not be null.overwrite - to overwrite the file if it already exists.FileHandler.copyFile(String, String, boolean)public void copyFile(String source, String target, org.apache.tools.ant.types.FilterChain filterChain)
FileHander#copyFile(String, String, FilterChain)public void copyFile(String source, String target, org.apache.tools.ant.types.FilterChain filterChain, String encoding)
copyFile in interface FileHandlersource - the file to copy from. Must not be nulltarget - the file to copy to. Must not be nullfilterChain - the filterChain to use. Must not be nullencoding - The character encoding to use, may be null or empty to use the
platform's default encoding.FileHander#copyFile(String, String, FilterChain, String)public void copyDirectory(String source, String target)
copyDirectory in interface FileHandlersource - the directory to copy from. Must not be null.target - the directory to copy to. Must not be null.FileHandler.copyDirectory(String, String)public void copyDirectory(String source, String target, List<String> excludes)
copyDirectory in interface FileHandlersource - the directory to copy from. Must not be null.target - the directory to copy to. Must not be null.excludes - the list of files to be excluded. Each entry in the list is an Ant file pattern.FileHandler.copyDirectory(String, String)public void copyDirectory(String source, String target, org.apache.tools.ant.types.FilterChain filterChain, String encoding)
copyDirectory in interface FileHandlersource - the directory to copy from. Must not be nulltarget - the directory to copy to. Must not be nullfilterChain - the filterChain to use. Must not be nullencoding - The character encoding to use, may be null or empty to use the
platform's default encoding.FileHander#copyDirectory(String, String, FilterChain, String)public String createDirectory(String parentDir, String name)
createDirectory in interface FileHandlerparentDir - The directory in which the new directory should be createdname - The name of the directory to createFileHandler.createDirectory(String, String)public void copy(InputStream in, OutputStream out, int bufSize)
copy in interface FileHandlerin - InputStream to copy data fromout - OutputStream to copy data tobufSize - size of the copy bufferFileHandler.copy(java.io.InputStream, java.io.OutputStream, int)public void copy(InputStream in, OutputStream out)
copy in interface FileHandlerin - InputStream to copy data fromout - OutputStream to copy data toFileHandler.copy(java.io.InputStream, java.io.OutputStream, int)public void replaceInFile(String file, Map<String,String> replacements, String encoding) throws CargoException
replaceInFile in interface FileHandlerfile - File to replace in.replacements - Map containing replacements.encoding - The character encoding to use, may be null or empty to use the
platform's default encoding.CargoException - If anything fails, most notably if one of the replacements does not
exist in the file.FileHandler.replaceInFile(String, Map, String)public void replaceInFile(String file, Map<String,String> replacements, String encoding, boolean ignoreNonExistingProperties) throws CargoException
replaceInFile in interface FileHandlerfile - File to replace in.replacements - Map containing replacements.encoding - The character encoding to use, may be null or empty to use the
platform's default encoding.ignoreNonExistingProperties - Whether to ignore if one of the keys cannot be found.CargoException - If anything fails, most notably if one of the replacements does not
exist in the file.FileHandler.replaceInFile(String, Map, String, boolean)public void replaceInXmlFile(String file, Map<FileHandler.XmlReplacement,String> replacements) throws CargoException
replaceInXmlFile in interface FileHandlerfile - File to replace in.replacements - Map containing XML replacements.CargoException - If anything fails, most notably if one of the replacements does not
exist in the file.FileHandler.replaceInXmlFile(String, Map)public void replaceInXmlFile(String file, Map<FileHandler.XmlReplacement,String> replacements, boolean ignoreNonExistingProperties) throws CargoException
replaceInXmlFile in interface FileHandlerfile - File to replace in.replacements - Map containing XML replacements.ignoreNonExistingProperties - Whether to ignore if one of the keys cannot be found.CargoException - If anything fails, most notably if one of the replacements does not
exist in the file.FileHandler.replaceInXmlFile(String, Map, boolean)public String getTmpPath(String name)
getTmpPath in interface FileHandlername - The name of the directory to compute inside the tmp directoryFileHandler.getTmpPath(String)public String createUniqueTmpDirectory()
createUniqueTmpDirectory in interface FileHandlerFileHandler.createUniqueTmpDirectory()public void delete(String path)
delete in interface FileHandlerpath - the path to the file or directory to removeFileHandler.delete(String)public long getSize(String file)
getSize in interface FileHandlerfile - the file for which to get the sizeFileHandler.getSize(String)public InputStream getInputStream(String file)
getInputStream in interface FileHandlerfile - the file for which to get an InputStream forFileHandler.getInputStream(String)public OutputStream getOutputStream(String file)
getOutputStream in interface FileHandlerfile - the file for which to get an OutputStream forFileHandler.getOutputStream(String)public String append(String path, String suffixToAppend)
append in interface FileHandlerpath - the path to append tosuffixToAppend - the suffix to append to the pathFileHandler.append(String, String)public void mkdirs(String path)
mkdirs in interface FileHandlerpath - the path for which to create all directories leading to itFileHandler.mkdirs(String)public String getParent(String path)
getParent in interface FileHandlerpath - the path for which to return its parentFileHandler.getParent(String)public boolean exists(String path)
exists in interface FileHandlerpath - the path to check the existence forFileHandler.exists(String)public void createFile(String file)
createFile in interface FileHandlerfile - the file to createFileHandler.createFile(String)public boolean isDirectoryEmpty(String dir)
isDirectoryEmpty in interface FileHandlerdir - the directory to checkFileHandler.isDirectoryEmpty(String)public String getName(String file)
getName in interface FileHandlerfile - the file name for which to return the file nameFileHandler.getName(String)public String getURL(String path)
getURL in interface FileHandlerpath - the path for which to return the URLFileHandler.getURL(String)public boolean isDirectory(String path)
isDirectory in interface FileHandlerpath - the path to verifyFileHandler.isDirectory(String)public String[] getChildren(String directory)
getChildren in interface FileHandlerdirectory - the directory for which to return all childrenFileHandler.getChildren(String)public String getAbsolutePath(String path)
getAbsolutePath in interface FileHandlerpath - - what to extract the file path fromFileHandler.getAbsolutePath(String)public String readTextFile(String file, String encoding)
readTextFile in interface FileHandlerfile - the file for which to load into a String object.encoding - The character encoding to use, may be null or empty to use the
platform's default encoding.FileHandler.readTextFile(String, String)public void writeTextFile(String file, String content, String encoding)
writeTextFile in interface FileHandlerfile - the file in which to write the String object.content - String to write into the file.encoding - The character encoding to use, may be null or empty to use the
platform's default encoding.FileHandler.writeTextFile(String, String, String)Copyright © 2004-2013 Codehaus. All Rights Reserved.