com.springsource.util.io
Class FileSystemUtils

java.lang.Object
  extended by com.springsource.util.io.FileSystemUtils

public final class FileSystemUtils
extends java.lang.Object

Utility methods for dealing with the file system.

Concurrent Semantics
Thread-safe.


Field Summary
private static java.lang.String URI_FILE_SCHEME
           
 
Constructor Summary
private FileSystemUtils()
           
 
Method Summary
static java.lang.String convertToCanonicalPath(java.lang.String path)
          Alias for convertToCanonicalPath(path, false) .
static java.lang.String convertToCanonicalPath(java.lang.String path, boolean verifyPathIsDirectory)
          Converts the supplied path to a canonical path, wrapping any IOExceptions in a FatalIOException.
static java.lang.String convertToCanonicalPath(java.net.URI uri)
          Converts the supplied URI to a canonical path, wrapping any IOExceptions in a FatalIOException.
static java.lang.String createDirectoryIfNecessary(java.lang.String path)
          Verifies that the directory with the supplied path exists, and if it does not exist, an attempt will be made to create it as well as any necessary parent directories.
static boolean deleteRecursively(java.io.File root)
          Delete the supplied File and, for directories, recursively delete any nested directories or files.
static boolean deleteRecursively(java.lang.String path)
          Delete the file referenced by the supplied path and, if the path refers to a directory, recursively delete any nested directories or files.
private static boolean doRecursiveDelete(java.io.File root)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URI_FILE_SCHEME

private static final java.lang.String URI_FILE_SCHEME
See Also:
Constant Field Values
Constructor Detail

FileSystemUtils

private FileSystemUtils()
Method Detail

convertToCanonicalPath

public static java.lang.String convertToCanonicalPath(java.lang.String path)
                                               throws FatalIOException
Alias for convertToCanonicalPath(path, false) .

Parameters:
path - the path to convert; may be null
Returns:
the canonical path or null if the supplied path was null
Throws:
FatalIOException - if a lower-level IOException is thrown.
See Also:
convertToCanonicalPath(String, boolean)

convertToCanonicalPath

public static java.lang.String convertToCanonicalPath(java.lang.String path,
                                                      boolean verifyPathIsDirectory)
                                               throws FatalIOException
Converts the supplied path to a canonical path, wrapping any IOExceptions in a FatalIOException.

Parameters:
path - the path to convert; may be null
verifyPathIsDirectory - true if the path should only refer to a directory
Returns:
the canonical path or null if the supplied path was null
Throws:
FatalIOException - if verifyPathIsDirectory is true and the supplied path is not a directory, or a lower-level IOException is thrown.

convertToCanonicalPath

public static java.lang.String convertToCanonicalPath(java.net.URI uri)
                                               throws FatalIOException
Converts the supplied URI to a canonical path, wrapping any IOExceptions in a FatalIOException.

Parameters:
uri - the path to convert; may be null
Returns:
the canonical path or null if the supplied URI was null
Throws:
FatalIOException - if a lower-level IOException is thrown.

createDirectoryIfNecessary

public static java.lang.String createDirectoryIfNecessary(java.lang.String path)
Verifies that the directory with the supplied path exists, and if it does not exist, an attempt will be made to create it as well as any necessary parent directories. As a convenience, the supplied path will be converted to a canonical path and returned.

Parameters:
path - the directory path; must not be null
Returns:
the canonical path to the directory

deleteRecursively

public static boolean deleteRecursively(java.io.File root)
Delete the supplied File and, for directories, recursively delete any nested directories or files.

Parameters:
root - the root File to delete.
Returns:
true if the File was deleted, otherwise false.
See Also:
deleteRecursively(String)

deleteRecursively

public static boolean deleteRecursively(java.lang.String path)
Delete the file referenced by the supplied path and, if the path refers to a directory, recursively delete any nested directories or files.

Parameters:
path - the path to the file or directory to delete.
Returns:
true if the file or directory was deleted, otherwise false.
See Also:
deleteRecursively(File)

doRecursiveDelete

private static boolean doRecursiveDelete(java.io.File root)