|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.io.FileUtils
org.mule.util.FileUtils
public class FileUtils
FileUtils
contains useful methods for dealing with files &
directories.
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_ENCODING
|
Fields inherited from class org.apache.commons.io.FileUtils |
---|
EMPTY_FILE_ARRAY, ONE_GB, ONE_KB, ONE_MB |
Constructor Summary | |
---|---|
FileUtils()
|
Method Summary | |
---|---|
static void |
closeQuietly(java.nio.channels.Channel channel)
Unconditionally close a Channel . |
static void |
copyFile(java.io.File srcFile,
java.io.File destFile,
boolean preserveFileDate)
Copies a file to a new location. |
static void |
copyStreamToFile(java.io.InputStream input,
java.io.File destination)
|
static java.io.File |
createFile(java.lang.String filename)
|
static boolean |
deleteTree(java.io.File dir)
Delete a file tree recursively. |
static boolean |
deleteTree(java.io.File dir,
java.lang.String[] topLevelDirsToIgnore)
Delete a file tree recursively. |
static void |
extractResources(java.lang.String resourceName,
java.lang.Class callingClass,
java.io.File outputDir,
boolean keepParentDirectory)
Extract the specified resource to the given directory for remain all directory struct |
static java.lang.String |
getResourcePath(java.lang.String resourceName,
java.lang.Class callingClass)
|
static java.lang.String |
getResourcePath(java.lang.String resourceName,
java.lang.Class callingClass,
java.lang.String encoding)
|
static boolean |
moveFileWithCopyFallback(java.io.File sourceFile,
java.io.File destinationFile)
Try to move a file by renaming with backup attempt by copying/deleting via NIO |
static java.io.File |
newFile(java.io.File parent,
java.lang.String child)
Workaround for JDK bug 4117557. |
static java.io.File |
newFile(java.lang.String pathName)
Workaround for JDK bug 4117557. |
static java.io.File |
newFile(java.lang.String parent,
java.lang.String child)
Workaround for JDK bug 4117557. |
static java.io.File |
newFile(java.net.URI uri)
Workaround for JDK bug 4117557. |
static java.lang.String |
normalizeFilePath(java.net.URL url,
java.lang.String encoding)
Remove from uri to file prefix file:/ Add if need file separator to begin |
static java.io.File |
openDirectory(java.lang.String directory)
|
static java.lang.String |
prepareWinFilename(java.lang.String filename)
|
static boolean |
renameFile(java.io.File srcFile,
java.io.File destFile)
|
static boolean |
renameFile(java.lang.String srcFilePath,
java.lang.String destFilePath)
|
static boolean |
renameFileHard(java.io.File srcFile,
java.io.File destFile)
|
static boolean |
renameFileHard(java.lang.String srcFilePath,
java.lang.String destFilePath)
|
static void |
safeCopyFile(java.io.File in,
java.io.File out)
Copy in file to out file Don't use java.nio as READ_ONLY memory mapped files cannot be deleted |
static java.io.File |
stringToFile(java.lang.String filename,
java.lang.String data)
Reads the incoming String into a file at at the given destination. |
static java.io.File |
stringToFile(java.lang.String filename,
java.lang.String data,
boolean append)
|
static java.io.File |
stringToFile(java.lang.String filename,
java.lang.String data,
boolean append,
boolean newLine)
|
static void |
unzip(java.io.File archive,
java.io.File directory)
Unzip the specified archive to the given directory |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.lang.String DEFAULT_ENCODING
Constructor Detail |
---|
public FileUtils()
Method Detail |
---|
public static void copyStreamToFile(java.io.InputStream input, java.io.File destination) throws java.io.IOException
java.io.IOException
public static java.io.File createFile(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static java.lang.String prepareWinFilename(java.lang.String filename)
public static java.io.File openDirectory(java.lang.String directory) throws java.io.IOException
java.io.IOException
public static java.io.File stringToFile(java.lang.String filename, java.lang.String data) throws java.io.IOException
filename
- name and path of the file to createdata
- the contents of the file
java.io.IOException
- If the creating or writing to the file stream failspublic static java.io.File stringToFile(java.lang.String filename, java.lang.String data, boolean append) throws java.io.IOException
java.io.IOException
public static java.io.File stringToFile(java.lang.String filename, java.lang.String data, boolean append, boolean newLine) throws java.io.IOException
java.io.IOException
public static java.lang.String getResourcePath(java.lang.String resourceName, java.lang.Class callingClass) throws java.io.IOException
java.io.IOException
public static java.lang.String getResourcePath(java.lang.String resourceName, java.lang.Class callingClass, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static java.lang.String normalizeFilePath(java.net.URL url, java.lang.String encoding) throws java.io.UnsupportedEncodingException
url
- file uri to resourceencoding
- - Java encoding names
java.io.UnsupportedEncodingException
- if encoding is unknownpublic static boolean deleteTree(java.io.File dir)
dir
- dir to wipe out
public static boolean deleteTree(java.io.File dir, java.lang.String[] topLevelDirsToIgnore)
dir
- dir to wipe outtopLevelDirsToIgnore
- which top-level directories to ignore,
if null or empty then ignored
public static void unzip(java.io.File archive, java.io.File directory) throws java.io.IOException
java.io.IOException
public static java.io.File newFile(java.lang.String pathName)
java.io.File class
.
No physical file created in this method.
File
public static java.io.File newFile(java.net.URI uri)
java.io.File class
.
No physical file created in this method.
File
public static java.io.File newFile(java.io.File parent, java.lang.String child)
java.io.File class
.
No physical file created in this method.
File
public static java.io.File newFile(java.lang.String parent, java.lang.String child)
java.io.File class
.
No physical file created in this method.
File
public static void extractResources(java.lang.String resourceName, java.lang.Class callingClass, java.io.File outputDir, boolean keepParentDirectory) throws java.io.IOException
resourceName
- - full resource namecallingClass
- - classloader for this class is usedoutputDir
- - extract to this directorykeepParentDirectory
- true - full structure of directories is kept; false - file - removed all directories, directory - started from resource point
java.io.IOException
- if any errorspublic static boolean renameFileHard(java.lang.String srcFilePath, java.lang.String destFilePath)
public static boolean renameFileHard(java.io.File srcFile, java.io.File destFile)
public static boolean renameFile(java.lang.String srcFilePath, java.lang.String destFilePath)
public static boolean renameFile(java.io.File srcFile, java.io.File destFile)
public static boolean moveFileWithCopyFallback(java.io.File sourceFile, java.io.File destinationFile)
public static void safeCopyFile(java.io.File in, java.io.File out) throws java.io.IOException
in
- out
-
java.io.IOException
public static void copyFile(java.io.File srcFile, java.io.File destFile, boolean preserveFileDate) throws java.io.IOException
This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.
srcFile
- an existing file to copy, must not be null
destFile
- the new file, must not be null
preserveFileDate
- true if the file date of the copy should be the same
as the original
java.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalid
java.io.IOException
- if an IO error occurs during copyingFileUtils.copyFileToDirectory(File, File, boolean)
public static void closeQuietly(java.nio.channels.Channel channel)
Channel
.
Equivalent to Channel.close()
, except any exceptions will be ignored.
This is typically used in finally blocks.
channel
- the Channel to close, may be null or already closed
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |