Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.mule.util
Class FileUtils

    java.lang.Object
      org.apache.commons.io.FileUtils
          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` | `closeQuietly(Channel channel)` Unconditionally close a `Channel`.
`static void` | `copyFile(File srcFile, File destFile, boolean preserveFileDate)` Copies a file to a new location.
`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` | `moveFileWithCopyFallback(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, copyDirectory, copyDirectory, copyDirectoryToDirectory, copyFile, copyFileToDirectory, copyFileToDirectory, copyURLToFile, deleteDirectory, deleteQuietly, forceDelete, forceDeleteOnExit, forceMkdir, isFileNewer, isFileNewer, isFileNewer, isFileOlder, isFileOlder, isFileOlder, iterateFiles, iterateFiles, lineIterator, lineIterator, listFiles, listFiles, moveDirectory, moveDirectoryToDirectory, moveFile, moveFileToDirectory, moveToDirectory, 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 String DEFAULT_ENCODING

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)

### moveFileWithCopyFallback

    public static boolean moveFileWithCopyFallback(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`

### copyFile

    public static void copyFile(File srcFile,
                                File destFile,
                                boolean preserveFileDate)
                         throws IOException

  Copies a file to a new location.

  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.

  Parameters:
    `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
  Throws:
    `NullPointerException` - if source or destination is `null`
    `IOException` - if source or destination is invalid
    `IOException` - if an IO error occurs during copying
  See Also:
    `FileUtils.copyFileToDirectory(File, File, boolean)`

### closeQuietly

    public static void closeQuietly(Channel channel)

  Unconditionally close a `Channel`.

  Equivalent to `Channel.close()`, except any exceptions will be ignored. This is typically used in finally blocks.

  Parameters:
    `channel` - the Channel to close, may be null or already closed

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2010 MuleSoft, Inc.. All Rights Reserved.