net.lucidviews.util.io
Class FilePaths

java.lang.Object
  extended by net.lucidviews.util.io.FilePaths

public class FilePaths
extends Object

A collection of methods for manipualting paths to files and folders.

Since:
1.3
Version:
$Revision: 1.1.2.1 $
Author:
Stephen Battey

Field Summary
static Map<Character,Character> SPECIAL_CHARACTER_REPLACEMENTS
          A default mapping of special characters to alternative, non-special characters.
static String SPECIAL_CHARACTERS
          The special characters that are reserved for file system paths in the operating system that is running this program.
protected static Map<String,String> SPECIAL_CHARACTERS_BY_OS
          A lookup table of special characters that are reserved for file system paths, indexed by the name of the operating system to which the reserved characters apply.
 
Constructor Summary
protected FilePaths()
          The default constructor.
 
Method Summary
static String getSpecialChars()
          Get the special (reserved) characters for file system paths for the operating system that is running this program.
static String getSpecialChars(String osName)
          Get the special (reserved) characters for file system paths for a given operating system.
static boolean isSamePath(File file1, File file2)
          Check if two files point to the same location.
static String validateFileName(String fileName)
          Create a valid name for a file, either replacing any illegal (reserved) characters in the original name with the default replacement characters or removing the illegal characters entirely.
static String validateFileName(String fileName, Map<Character,Character> replacementCharacters)
          Create a valid name for a file, either replacing any illegal (reserved) characters in the original name with the suggested replacement characters or removing the illegal characters entirely.
static File validateFilePath(File file)
          Create a valid file path, either replacing any illegal (reserved) characters in the original path with the default replacement characters or removing the illegal characters entirely.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPECIAL_CHARACTERS_BY_OS

protected static final Map<String,String> SPECIAL_CHARACTERS_BY_OS
A lookup table of special characters that are reserved for file system paths, indexed by the name of the operating system to which the reserved characters apply.


SPECIAL_CHARACTERS

public static final String SPECIAL_CHARACTERS
The special characters that are reserved for file system paths in the operating system that is running this program.


SPECIAL_CHARACTER_REPLACEMENTS

public static final Map<Character,Character> SPECIAL_CHARACTER_REPLACEMENTS
A default mapping of special characters to alternative, non-special characters.

Constructor Detail

FilePaths

protected FilePaths()
The default constructor.

Method Detail

isSamePath

public static final boolean isSamePath(File file1,
                                       File file2)
                                throws IOException
Check if two files point to the same location.

Parameters:
file1 - the first file
file2 - the other file
Returns:
true if the two Files reference the same location
Throws:
IOException - if the file paths cannot be resolved into canonical form

validateFilePath

public static File validateFilePath(File file)
Create a valid file path, either replacing any illegal (reserved) characters in the original path with the default replacement characters or removing the illegal characters entirely.

Parameters:
file - the original file path
Returns:
a valid file path
See Also:
SPECIAL_CHARACTER_REPLACEMENTS

validateFileName

public static String validateFileName(String fileName)
Create a valid name for a file, either replacing any illegal (reserved) characters in the original name with the default replacement characters or removing the illegal characters entirely.

Parameters:
fileName - the original file name
Returns:
a valid file name
See Also:
SPECIAL_CHARACTER_REPLACEMENTS

validateFileName

public static String validateFileName(String fileName,
                                      Map<Character,Character> replacementCharacters)
Create a valid name for a file, either replacing any illegal (reserved) characters in the original name with the suggested replacement characters or removing the illegal characters entirely.

Parameters:
fileName - the original file name
replacementCharacters - characters used to replace illegal characters
Returns:
a valid file name

getSpecialChars

public static String getSpecialChars()
Get the special (reserved) characters for file system paths for the operating system that is running this program.

Returns:
a string containing the special (reserved) characters

getSpecialChars

public static String getSpecialChars(String osName)
                              throws UnsupportedOperationException
Get the special (reserved) characters for file system paths for a given operating system.

Parameters:
osName - the name of the operating system (version is optional, e.g. "Windows" or "Windows XP" will both find the settings for Windows)
Returns:
a string containing the special (reserved) characters
Throws:
UnsupportedOperationException - if the operating system is unknown (not supported)