02/28/2005
 

com.vignette.portal.util
Class FileUtils

java.lang.Object
  |
  +--com.vignette.portal.util.FileUtils

public final class FileUtils
extends Object

File management utilities.


Constructor Summary
FileUtils()
           
 
Method Summary
static String appendSlash(String dir)
          Add a trailing slash (File.separator) on given string to make it a directory.
static void copy(File source, File destination)
          Copy the source file or directory to the destination.
static boolean delete(File file)
          Delete the given file or directory, recursively.
static boolean deleteDirectoryContents(File file)
          Delete the files and subdirectories of the given directory, recursively.
static String fixSlashes(String str)
          Change any forward or backward slashes into the File.separator.
static String generateUniqueName()
          Generate a file name that's unique through all calls to this method (assuming nobody tampers with the clock).
static URL toFileURL(String file_path)
          Get the file URL version of the specified local file path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

copy

public static void copy(File source,
                        File destination)
Copy the source file or directory to the destination. Does not delete the destination if it already exists.
Parameters:
source - The file to be copied.
destination - The file to which source will be copied.

delete

public static boolean delete(File file)
Delete the given file or directory, recursively.

If there's an error, continue to try to delete all files it can possibly delete.
Parameters:
file - The file to be deleted.
Returns:
true if the specified file was deleted successfully.

deleteDirectoryContents

public static boolean deleteDirectoryContents(File file)
Delete the files and subdirectories of the given directory, recursively. This will not delete the directory itself, however.

If there's an error, continue to try to delete all files it can possibly delete. This will return 'false' if 'file' is not a directory.
Parameters:
file - The directory in which to delete all contents.
Returns:
true if the operation was successful.

toFileURL

public static URL toFileURL(String file_path)
Get the file URL version of the specified local file path. Returns null if file_path is null or an empty string. Also returns null if the given file_path cannot generate a well formed URL.
Parameters:
file_path - The file path of a local file on the file system.
Returns:
A URL representation of the specified local file path.

generateUniqueName

public static String generateUniqueName()
Generate a file name that's unique through all calls to this method (assuming nobody tampers with the clock).
Returns:
A unique random filename.

fixSlashes

public static String fixSlashes(String str)
Change any forward or backward slashes into the File.separator.
Parameters:
str - The string on which to fix slashes.
Returns:
A String matching str but with all forward or backward slashes replaced with File.separator.

appendSlash

public static String appendSlash(String dir)
Add a trailing slash (File.separator) on given string to make it a directory. Does not add slash if one exists.

The returned string is a new String -- it will never be the same object as the dir parameter.

Returns slash if dir is null or is whitespace.
Parameters:
dir - The directory string on which to append a File.seperator if required.
Returns:
A new directory string if the File.seperator was appended, otherwise returns the value passed in at dir.

02/28/2005
 

Copyright and Trademark Notices