org.mule.util
Class FileUtils

java.lang.Object
  extended by org.apache.commons.io.FileUtils
      extended by org.mule.util.FileUtils

public class FileUtils
extends FileUtils

FileUtils contains useful methods for dealing with files & directories.


Field Summary
static 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 copyStreamToFile(InputStream input, File destination)
           
static File createFile(String filename)
           
static boolean deleteTree(File dir)
          Delete a file tree recursively.
static boolean deleteTree(File dir, String[] topLevelDirsToIgnore)
          Delete a file tree recursively.
static void extractResources(String resourceName, Class callingClass, File outputDir, boolean keepParentDirectory)
          Extract the specified resource to the given directory for remain all directory struct
static String getResourcePath(String resourceName, Class callingClass)
           
static String getResourcePath(String resourceName, Class callingClass, String encoding)
           
static boolean moveFile(File sourceFile, File destinationFile)
          Try to move a file by renaming with backup attempt by copying/deleting via NIO
static File newFile(File parent, String child)
          Workaround for JDK bug 4117557.
static File newFile(String pathName)
          Workaround for JDK bug 4117557.
static File newFile(String parent, String child)
          Workaround for JDK bug 4117557.
static File newFile(URI uri)
          Workaround for JDK bug 4117557.
static String normalizeFilePath(URL url, String encoding)
          Remove from uri to file prefix file:/ Add if need file separator to begin
static File openDirectory(String directory)
           
static String prepareWinFilename(String filename)
           
static boolean renameFile(File srcFile, File destFile)
           
static boolean renameFile(String srcFilePath, String destFilePath)
           
static boolean renameFileHard(File srcFile, File destFile)
           
static boolean renameFileHard(String srcFilePath, String destFilePath)
           
static void safeCopyFile(File in, File out)
          Copy in file to out file Don't use java.nio as READ_ONLY memory mapped files cannot be deleted
static File stringToFile(String filename, String data)
          Reads the incoming String into a file at at the given destination.
static File stringToFile(String filename, String data, boolean append)
           
static File stringToFile(String filename, String data, boolean append, boolean newLine)
           
static void unzip(File archive, File directory)
          Unzip the specified archive to the given directory
 
Methods inherited from class org.apache.commons.io.FileUtils
byteCountToDisplaySize, checksum, checksumCRC32, cleanDirectory, contentEquals, convertFileCollectionToFileArray, copyDirectory, copyDirectory, copyDirectoryToDirectory, copyFile, copyFile, copyFileToDirectory, copyFileToDirectory, copyURLToFile, deleteDirectory, forceDelete, forceDeleteOnExit, forceMkdir, isFileNewer, isFileNewer, isFileNewer, isFileOlder, isFileOlder, isFileOlder, iterateFiles, iterateFiles, lineIterator, lineIterator, listFiles, listFiles, openInputStream, openOutputStream, readFileToByteArray, readFileToString, readFileToString, readLines, readLines, sizeOfDirectory, toFile, toFiles, touch, toURLs, waitFor, writeByteArrayToFile, writeLines, writeLines, writeLines, writeLines, writeStringToFile, writeStringToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENCODING

public static final String DEFAULT_ENCODING
See Also:
Constant Field Values
Constructor Detail

FileUtils

public FileUtils()
Method Detail

copyStreamToFile

public static void copyStreamToFile(InputStream input,
                                    File destination)
                             throws IOException
Throws:
IOException

createFile

public static File createFile(String filename)
                       throws IOException
Throws:
IOException

prepareWinFilename

public static String prepareWinFilename(String filename)

openDirectory

public static File openDirectory(String directory)
                          throws IOException
Throws:
IOException

stringToFile

public static File stringToFile(String filename,
                                String data)
                         throws IOException
Reads the incoming String into a file at at the given destination.

Parameters:
filename - name and path of the file to create
data - the contents of the file
Returns:
the new file.
Throws:
IOException - If the creating or writing to the file stream fails

stringToFile

public static File stringToFile(String filename,
                                String data,
                                boolean append)
                         throws IOException
Throws:
IOException

stringToFile

public static File stringToFile(String filename,
                                String data,
                                boolean append,
                                boolean newLine)
                         throws IOException
Throws:
IOException

getResourcePath

public static String getResourcePath(String resourceName,
                                     Class callingClass)
                              throws IOException
Throws:
IOException

getResourcePath

public static String getResourcePath(String resourceName,
                                     Class callingClass,
                                     String encoding)
                              throws IOException
Throws:
IOException

normalizeFilePath

public static String normalizeFilePath(URL url,
                                       String encoding)
                                throws UnsupportedEncodingException
Remove from uri to file prefix file:/ Add if need file separator to begin

Parameters:
url - file uri to resource
encoding - - Java encoding names
Returns:
normalized file path
Throws:
UnsupportedEncodingException - if encoding is unknown

deleteTree

public static boolean deleteTree(File dir)
Delete a file tree recursively.

Parameters:
dir - dir to wipe out
Returns:
false when the first unsuccessful attempt encountered

deleteTree

public static boolean deleteTree(File dir,
                                 String[] topLevelDirsToIgnore)
Delete a file tree recursively. This method additionally tries to be gentle with specified top-level dirs. E.g. this is the case when a transaction manager asynchronously handles the recovery log, and the test wipes out everything, leaving the transaction manager puzzled.

Parameters:
dir - dir to wipe out
topLevelDirsToIgnore - which top-level directories to ignore, if null or empty then ignored
Returns:
false when the first unsuccessful attempt encountered

unzip

public static void unzip(File archive,
                         File directory)
                  throws IOException
Unzip the specified archive to the given directory

Throws:
IOException

newFile

public static File newFile(String pathName)
Workaround for JDK bug 4117557. More in-context information at MULE-1112

Factory methods correspond to constructors of the java.io.File class. No physical file created in this method.

See Also:
File

newFile

public static File newFile(URI uri)
Workaround for JDK bug 4117557. More in-context information at MULE-1112

Factory methods correspond to constructors of the java.io.File class. No physical file created in this method.

See Also:
File

newFile

public static File newFile(File parent,
                           String child)
Workaround for JDK bug 4117557. More in-context information at MULE-1112

Factory methods correspond to constructors of the java.io.File class. No physical file created in this method.

See Also:
File

newFile

public static File newFile(String parent,
                           String child)
Workaround for JDK bug 4117557. More in-context information at MULE-1112

Factory methods correspond to constructors of the java.io.File class. No physical file created in this method.

See Also:
File

extractResources

public static void extractResources(String resourceName,
                                    Class callingClass,
                                    File outputDir,
                                    boolean keepParentDirectory)
                             throws IOException
Extract the specified resource to the given directory for remain all directory struct

Parameters:
resourceName - - full resource name
callingClass - - classloader for this class is used
outputDir - - extract to this directory
keepParentDirectory - true - full structure of directories is kept; false - file - removed all directories, directory - started from resource point
Throws:
IOException - if any errors

renameFileHard

public static boolean renameFileHard(String srcFilePath,
                                     String destFilePath)

renameFileHard

public static boolean renameFileHard(File srcFile,
                                     File destFile)

renameFile

public static boolean renameFile(String srcFilePath,
                                 String destFilePath)

renameFile

public static boolean renameFile(File srcFile,
                                 File destFile)

moveFile

public static boolean moveFile(File sourceFile,
                               File destinationFile)
Try to move a file by renaming with backup attempt by copying/deleting via NIO


safeCopyFile

public static void safeCopyFile(File in,
                                File out)
                         throws IOException
Copy in file to out file Don't use java.nio as READ_ONLY memory mapped files cannot be deleted

Parameters:
in -
out -
Throws:
IOException


Copyright © 2003-2009 MuleSource, Inc.. All Rights Reserved.