org.apache.camel.util
Class FileUtil

java.lang.Object
  extended by org.apache.camel.util.FileUtil

public final class FileUtil
extends Object

File utilities.


Field Summary
static int BUFFER_SIZE
           
 
Method Summary
static String compactPath(String path)
          Compacts a path by stacking it and reducing .., and uses OS specific file separators (eg File.separator).
static String compactPath(String path, char separator)
          Compacts a path by stacking it and reducing .., and uses the given separator.
static void copyFile(File from, File to)
           
static boolean createNewFile(File file)
          Creates a new file.
static File createTempFile(String prefix, String suffix)
           
static File createTempFile(String prefix, String suffix, File parentDir)
           
static boolean deleteFile(File file)
           
static boolean hasLeadingSeparator(String name)
          Does the name start with a leading separator
static boolean isAbsolute(File file)
          Is the given file an absolute file.
static boolean isWindows()
           
static String normalizePath(String path)
          Normalizes the path to cater for Windows and other platforms
static String onlyPath(String name)
          Returns only the leading path (returns null if no path)
static boolean renameFile(File from, File to, boolean copyAndDeleteOnRenameFail)
          Renames a file.
static void shutdown()
          Shutdown and cleanup the temporary directory and removes any shutdown hooks in use.
static String stripExt(String name)
           
static String stripFirstLeadingSeparator(String name)
          Strip first leading separator
static String stripLeadingSeparator(String name)
          Strip any leading separators
static String stripPath(String name)
          Strips any leading paths
static String stripTrailingSeparator(String name)
          Strip any trailing separators
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

public static final int BUFFER_SIZE
See Also:
Constant Field Values
Method Detail

normalizePath

public static String normalizePath(String path)
Normalizes the path to cater for Windows and other platforms


isWindows

public static boolean isWindows()

createTempFile

public static File createTempFile(String prefix,
                                  String suffix)
                           throws IOException
Throws:
IOException

createTempFile

public static File createTempFile(String prefix,
                                  String suffix,
                                  File parentDir)
                           throws IOException
Throws:
IOException

stripLeadingSeparator

public static String stripLeadingSeparator(String name)
Strip any leading separators


hasLeadingSeparator

public static boolean hasLeadingSeparator(String name)
Does the name start with a leading separator


stripFirstLeadingSeparator

public static String stripFirstLeadingSeparator(String name)
Strip first leading separator


stripTrailingSeparator

public static String stripTrailingSeparator(String name)
Strip any trailing separators


stripPath

public static String stripPath(String name)
Strips any leading paths


stripExt

public static String stripExt(String name)

onlyPath

public static String onlyPath(String name)
Returns only the leading path (returns null if no path)


compactPath

public static String compactPath(String path)
Compacts a path by stacking it and reducing .., and uses OS specific file separators (eg File.separator).


compactPath

public static String compactPath(String path,
                                 char separator)
Compacts a path by stacking it and reducing .., and uses the given separator.


shutdown

public static void shutdown()
Shutdown and cleanup the temporary directory and removes any shutdown hooks in use.


renameFile

public static boolean renameFile(File from,
                                 File to,
                                 boolean copyAndDeleteOnRenameFail)
                          throws IOException
Renames a file.

Parameters:
from - the from file
to - the to file
copyAndDeleteOnRenameFail - whether to fallback and do copy and delete, if renameTo fails
Returns:
true if the file was renamed, otherwise false
Throws:
IOException - is thrown if error renaming file

copyFile

public static void copyFile(File from,
                            File to)
                     throws IOException
Throws:
IOException

deleteFile

public static boolean deleteFile(File file)

isAbsolute

public static boolean isAbsolute(File file)
Is the given file an absolute file.

Will also work around issue on Windows to consider files on Windows starting with a \ as absolute files. This makes the logic consistent across all OS platforms.

Parameters:
file - the file
Returns:
true if its an absolute path, false otherwise.

createNewFile

public static boolean createNewFile(File file)
                             throws IOException
Creates a new file.

Parameters:
file - the file
Returns:
true if created a new file, false otherwise
Throws:
IOException - is thrown if error creating the new file


Apache CAMEL