org.arakhne.vmutil
Class FileSystem

java.lang.Object
  extended by org.arakhne.vmutil.FileSystem

public class FileSystem
extends Object

An utility class that permits to deal with filenames.

Version:
6.3 (rev:285) 2011-10-14 12:02:41
Author:
Stéphane GALLAND
Maven Group Id:
org.arakhne.afc
Maven Artifact Id:
arakhneVmutils

Field Summary
static String CURRENT_DIRECTORY
          String which is representing the current directory in a relative path.
static String EXTENSION_SEPARATOR
          String used to specify a file extension.
static char EXTENSION_SEPARATOR_CHAR
          Character used to specify a file extension.
static String JAR_URL_FILE_ROOT
          Prefix used to join in a Jar URL the jar filename and the inside-jar filename.
static String PARENT_DIRECTORY
          String which is representing the parent directory in a relative path.
static String URL_PATH_SEPARATOR
          Character used to separate paths on an URL.
static char URL_PATH_SEPARATOR_CHAR
          Character used to separate paths on an URL.
 
Constructor Summary
FileSystem()
           
 
Method Summary
static File addExtension(File filename, String extension)
          Add the extension of to specified filename.
static URL addExtension(URL filename, String extension)
          Add the extension of to specified filename.
static String basename(File filename)
          Reply the basename of the specified file without the last extension.
static String basename(String filename)
          Reply the basename of the specified file without the last extension.
static String basename(URL filename)
          Reply the basename of the specified file without the last extension.
static URL convertFileToURL(File file)
          Replies an URL for the given file and translate it into a resource URL if the given file is inside the classpath.
static URL convertStringToUrl(String urlDescription, boolean allowResourceSearch)
          Deprecated. see convertStringToURL(String, boolean)
static URL convertStringToURL(String urlDescription, boolean allowResourceSearch)
          Convert a string to an URL according to several rules.
static URL convertStringToUrl(String urlDescription, boolean allowResourceSearch, boolean repliesFileURL)
          Deprecated. convertStringToURL(String, boolean, boolean)
static URL convertStringToURL(String urlDescription, boolean allowResourceSearch, boolean repliesFileURL)
          Convert a string to an URL according to several rules.
(package private) static URL convertStringToURL(String urlDescription, boolean allowResourceSearch, boolean repliesFileURL, boolean supportWindowsPaths)
          Convert a string to an URL according to several rules.
static File convertUrlToFile(URL url)
          Deprecated. convertURLToFile(URL)
static File convertURLToFile(URL url)
          Convert an URL which represents a local file into a File.
static void copy(File in, File out)
          Copy the first file into the second file.
static void copy(InputStream in, int inSize, FileOutputStream out)
          Copy the first file into the second file.
static void copy(URL in, File out)
          Copy the first file into the second file.
static File createTempDirectory(String prefix, String suffix)
          Create an empty directory in the default temporary-file directory, using the given prefix and suffix to generate its name.
static File createTempDirectory(String prefix, String suffix, File directory)
          Creates a new empty directory in the specified directory, using the given prefix and suffix strings to generate its name.
static void delete(File file)
          Delete the given directory and all its subdirectories.
static void deleteOnExit(File file)
          Delete the given directory and all its subdirectories when the JVM is exiting.
static URL dirname(File filename)
          Replies the dirname of the specified file.
static URL dirname(URL filename)
          Replies the dirname of the specified file.
static String extension(File filename)
          Reply the extension of the specified file.
static String extension(URL filename)
          Reply the extension of the specified file.
static String[] extensions(File filename)
          Reply all the extensions of the specified file.
static String[] extensions(URL filename)
          Reply all the extensions of the specified file.
static void fileCopy(File in, File out)
          Deprecated. copy(File, File)
static void fileCopy(URL in, File out)
          Deprecated. copy(URL, File)
static char getFileExtensionCharacter()
          Replies the character used to separate the basename and the file extension.
static File getJarFile(URL url)
          Replies the file part of the jar-scheme URL.
static URL getJarURL(URL url)
          Replies the jar part of the jar-scheme URL.
static URL getParentURL(URL url)
          Replies the parent URL for the given URL.
static File getSystemConfigurationDirectoryFor(String software)
          Replies the system configuration directory for the specified software.
static String getSystemConfigurationDirectoryNameFor(String software)
          Replies the user configuration directory for the specified software.
static File getSystemSharedLibraryDirectoryFor(String software)
          Replies the system shared library directory for the specified software.
static String getSystemSharedLibraryDirectoryNameFor(String software)
          Replies the system shared library directory for the specified software.
static File getUserConfigurationDirectoryFor(String software)
          Replies the user configuration directory for the specified software.
static String getUserConfigurationDirectoryNameFor(String software)
          Replies the user configuration directory for the specified software.
static File getUserHomeDirectory()
          Replies the user home directory.
static String getUserHomeDirectoryName()
          Replies the user home directory.
static boolean hasExtension(File filename, String extension)
          Replies if the specified file has the specified extension.
static boolean hasExtension(URL filename, String extension)
          Replies if the specified file has the specified extension.
static boolean isCaseSensitiveFilenameSystem()
          Replies if the current operating system uses case-sensitive filename.
static boolean isFileBasedScheme(URISchemeType scheme)
          Deprecated. see URISchemeType.isFileBasedScheme()
static boolean isFileBasedURL(URL url)
          Deprecated. see URISchemeType.isFileBasedScheme()
static boolean isJarURL(URL url)
          Replies if the given URL has a jar scheme.
static boolean isWindowsNativeFilename(String filename)
          Replies if the given string contains a Windows® native long filename.
static File join(File fileBase, File... elements)
          Join the parts of a path and append them to the given File.
static File join(File fileBase, String... elements)
          Join the parts of a path and append them to the given File.
static URL join(URL urlBase, File... elements)
          Join the parts of a path and append them to the given URL.
static URL join(URL urlBase, String... elements)
          Join the parts of a path and append them to the given URL.
static String largeBasename(File filename)
          Replies the basename of the specified file with the extension.
static String largeBasename(String filename)
          Replies the basename of the specified file with the extension.
static String largeBasename(URL filename)
          Replies the basename of the specified file with the extension.
static File makeAbsolute(File filename, File current)
          Make the given filename absolute from the given root if it is not already absolute.
static URL makeAbsolute(File filename, URL current)
          Make the given filename absolute from the given root if it is not already absolute.
static URL makeAbsolute(URL filename, File current)
          Make the given filename absolute from the given root if it is not already absolute.
static URL makeAbsolute(URL filename, URL current)
          Make the given filename absolute from the given root if it is not already absolute.
static URL makeCanonicalURL(URL url)
           A canonical pathname is both absolute and unique.
static File makeRelative(File filenameToMakeRelative, File rootPath)
          Make the given filename relative to the given root path.
static File makeRelative(File filenameToMakeRelative, URL rootPath)
          Make the given filename relative to the given root path.
static File makeRelative(URL filenameToMakeRelative, URL rootPath)
          Make the given filename relative to the given root path.
static File normalizeWindowsNativeFilename(String filename)
          Normalize the given string contains a Windows® native long filename and replies a Java-standard version.
static File removeExtension(File filename)
          Remove the extension from the specified filename.
static URL removeExtension(URL filename)
          Remove the extension from the specified filename.
static File replaceExtension(File filename, String extension)
          Replace the extension of the specified filename by the given extension.
static URL replaceExtension(URL filename, String extension)
          Replace the extension of the specified filename by the given extension.
static String shortBasename(File filename)
          Reply the basename of the specified file without all the extensions.
static String shortBasename(String filename)
          Reply the basename of the specified file without all the extensions.
static String shortBasename(URL filename)
          Reply the basename of the specified file without all the extensions.
static String[] split(File filename)
          Replies the parts of a path.
static String[] split(URL filename)
          Replies the parts of a path.
static URL toJarURL(File jarFile, File insideFile)
          Replies the jar-schemed URL composed of the two given components.
static URL toJarURL(File jarFile, String insideFile)
          Replies the jar-schemed URL composed of the two given components.
static URL toJarURL(URL jarFile, File insideFile)
          Replies the jar-schemed URL composed of the two given components.
static URL toJarURL(URL jarFile, String insideFile)
          Replies the jar-schemed URL composed of the two given components.
static URL toShortestURL(URL url)
          Replies an URL for the given url and translate it into a resource URL if the given file is inside the classpath.
static void undeleteOnExit(File file)
          Cancel the deletion of the given directory and all its subdirectories when the JVM is exiting.
static void unzipFile(File input, File output)
          Unzip a file into the output directory.
static void unzipFile(InputStream input, File output)
          Unzip the given stream and write out the file in the output.
static void zipFile(File input, File output)
          Create a zip file from the given input file.
static void zipFile(File input, OutputStream output)
          Create a zip file from the given input file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXTENSION_SEPARATOR_CHAR

public static final char EXTENSION_SEPARATOR_CHAR
Character used to specify a file extension.

See Also:
Constant Field Values

CURRENT_DIRECTORY

public static final String CURRENT_DIRECTORY
String which is representing the current directory in a relative path.

See Also:
Constant Field Values

PARENT_DIRECTORY

public static final String PARENT_DIRECTORY
String which is representing the parent directory in a relative path.

See Also:
Constant Field Values

URL_PATH_SEPARATOR_CHAR

public static final char URL_PATH_SEPARATOR_CHAR
Character used to separate paths on an URL.

See Also:
Constant Field Values

URL_PATH_SEPARATOR

public static final String URL_PATH_SEPARATOR
Character used to separate paths on an URL.

See Also:
Constant Field Values

EXTENSION_SEPARATOR

public static final String EXTENSION_SEPARATOR
String used to specify a file extension.

See Also:
Constant Field Values

JAR_URL_FILE_ROOT

public static final String JAR_URL_FILE_ROOT
Prefix used to join in a Jar URL the jar filename and the inside-jar filename.

See Also:
Constant Field Values
Constructor Detail

FileSystem

public FileSystem()
Method Detail

isJarURL

public static boolean isJarURL(URL url)
Replies if the given URL has a jar scheme.

Parameters:
url -
Returns:
true if the given URL uses a jar scheme.

getJarURL

public static URL getJarURL(URL url)
Replies the jar part of the jar-scheme URL.

Parameters:
url -
Returns:
the URL of the jar file in the given URL, or null if the given URL does not use jar scheme.

getJarFile

public static File getJarFile(URL url)
Replies the file part of the jar-scheme URL.

Parameters:
url -
Returns:
the file in the given URL, or null if the given URL does not use jar scheme.

toJarURL

public static URL toJarURL(File jarFile,
                           File insideFile)
                    throws MalformedURLException
Replies the jar-schemed URL composed of the two given components.

Parameters:
jarFile - is the URL to the jar file.
insideFile - is the name of the file inside the jar.
Returns:
the jar-schemed URL.
Throws:
MalformedURLException - when the URL is malformed.

toJarURL

public static URL toJarURL(File jarFile,
                           String insideFile)
                    throws MalformedURLException
Replies the jar-schemed URL composed of the two given components.

Parameters:
jarFile - is the URL to the jar file.
insideFile - is the name of the file inside the jar.
Returns:
the jar-schemed URL.
Throws:
MalformedURLException - when the URL is malformed.

toJarURL

public static URL toJarURL(URL jarFile,
                           File insideFile)
                    throws MalformedURLException
Replies the jar-schemed URL composed of the two given components.

Parameters:
jarFile - is the URL to the jar file.
insideFile - is the name of the file inside the jar.
Returns:
the jar-schemed URL.
Throws:
MalformedURLException - when the URL is malformed.

toJarURL

public static URL toJarURL(URL jarFile,
                           String insideFile)
                    throws MalformedURLException
Replies the jar-schemed URL composed of the two given components.

Parameters:
jarFile - is the URL to the jar file.
insideFile - is the name of the file inside the jar.
Returns:
the jar-schemed URL.
Throws:
MalformedURLException - when the URL is malformed.

isCaseSensitiveFilenameSystem

public static boolean isCaseSensitiveFilenameSystem()
Replies if the current operating system uses case-sensitive filename.

Returns:
true if the filenames on the current file system are case sensitive, otherwise false

getFileExtensionCharacter

public static char getFileExtensionCharacter()
Replies the character used to separate the basename and the file extension.

Returns:
the character used to separate the basename and the file extension.

dirname

public static URL dirname(File filename)
Replies the dirname of the specified file.

Parameters:
filename - is the name to parse.
Returns:
the dirname of the specified file.
See Also:
shortBasename(File), largeBasename(File), basename(File), extension(File)

dirname

public static URL dirname(URL filename)
Replies the dirname of the specified file.

Parameters:
filename - is the name to parse.
Returns:
the dirname of the specified file.
See Also:
shortBasename(URL), largeBasename(URL), basename(URL), extension(URL)

largeBasename

public static String largeBasename(String filename)
Replies the basename of the specified file with the extension.

Caution: This function does not support URL format.

Parameters:
filename - is the name to parse.
Returns:
the basename of the specified file with the extension.

largeBasename

public static String largeBasename(File filename)
Replies the basename of the specified file with the extension.

Parameters:
filename - is the name to parse.
Returns:
the basename of the specified file with the extension.

largeBasename

public static String largeBasename(URL filename)
Replies the basename of the specified file with the extension.

Parameters:
filename - is the name to parse.
Returns:
the basename of the specified file with the extension.

basename

public static String basename(String filename)
Reply the basename of the specified file without the last extension.

Caution: This function does not support URL format.

Parameters:
filename - is the name to parse.
Returns:
the basename of the specified file without the last extension.
See Also:
shortBasename(String), largeBasename(String)

basename

public static String basename(File filename)
Reply the basename of the specified file without the last extension.

Parameters:
filename - is the name to parse.
Returns:
the basename of the specified file without the last extension.
See Also:
shortBasename(File), largeBasename(File), dirname(File), extension(File)

basename

public static String basename(URL filename)
Reply the basename of the specified file without the last extension.

Parameters:
filename - is the name to parse.
Returns:
the basename of the specified file without the last extension.
See Also:
shortBasename(URL), largeBasename(URL), dirname(URL), extension(URL)

shortBasename

public static String shortBasename(String filename)
Reply the basename of the specified file without all the extensions.

Caution: This function does not support URL format.

Parameters:
filename - is the name to parse.
Returns:
the basename of the specified file without all the extensions.

shortBasename

public static String shortBasename(File filename)
Reply the basename of the specified file without all the extensions.

Parameters:
filename - is the name to parse.
Returns:
the basename of the specified file without all the extensions.

shortBasename

public static String shortBasename(URL filename)
Reply the basename of the specified file without all the extensions.

Parameters:
filename - is the name to parse.
Returns:
the basename of the specified file without all the extensions.

extension

public static String extension(File filename)
Reply the extension of the specified file.

Parameters:
filename - is the name to parse.
Returns:
the extension of the specified file
See Also:
shortBasename(File), largeBasename(File), basename(File), dirname(File), extensions(File)

extension

public static String extension(URL filename)
Reply the extension of the specified file.

Parameters:
filename - is the name to parse.
Returns:
the extension of the specified file
See Also:
shortBasename(URL), largeBasename(URL), basename(URL), dirname(URL), extensions(URL)

extensions

public static String[] extensions(File filename)
Reply all the extensions of the specified file.

Parameters:
filename - is the name to parse.
Returns:
the extensions of the specified file

extensions

public static String[] extensions(URL filename)
Reply all the extensions of the specified file.

Parameters:
filename - is the name to parse.
Returns:
the extensions of the specified file

split

public static String[] split(File filename)
Replies the parts of a path.

Parameters:
filename - is the name to parse.
Returns:
the parts of a path.

split

public static String[] split(URL filename)
Replies the parts of a path.

Parameters:
filename - is the name to parse.
Returns:
the parts of a path.

join

public static File join(File fileBase,
                        String... elements)
Join the parts of a path and append them to the given File.

Parameters:
fileBase - is the file to put as prefix.
elements - are the path's elements to join.
Returns:
the result of the join of the path's elements.

join

public static File join(File fileBase,
                        File... elements)
Join the parts of a path and append them to the given File.

Parameters:
fileBase - is the file to put as prefix.
elements - are the path's elements to join.
Returns:
the result of the join of the path's elements.

join

public static URL join(URL urlBase,
                       String... elements)
Join the parts of a path and append them to the given URL.

Parameters:
urlBase - is the url to put as prefix.
elements - are the path's elements to join.
Returns:
the result of the join of the path's elements.

join

public static URL join(URL urlBase,
                       File... elements)
Join the parts of a path and append them to the given URL.

Parameters:
urlBase - is the url to put as prefix.
elements - are the path's elements to join.
Returns:
the result of the join of the path's elements.

hasExtension

public static boolean hasExtension(File filename,
                                   String extension)
Replies if the specified file has the specified extension.

The test is dependent of the case-sensitive attribute of operating system.

Parameters:
filename - is the filename to parse
extension - is the extension to test.
Returns:
true if the given filename has the given extension, otherwise false

hasExtension

public static boolean hasExtension(URL filename,
                                   String extension)
Replies if the specified file has the specified extension.

The test is dependent of the case-sensitive attribute of operating system.

Parameters:
filename - is the filename to parse
extension - is the extension to test.
Returns:
true if the given filename has the given extension, otherwise false

removeExtension

public static File removeExtension(File filename)
Remove the extension from the specified filename.

Parameters:
filename - is the filename to parse.
Returns:
the filename without the extension.

removeExtension

public static URL removeExtension(URL filename)
Remove the extension from the specified filename.

Parameters:
filename - is the filename to parse.
Returns:
the filename without the extension.

replaceExtension

public static File replaceExtension(File filename,
                                    String extension)
Replace the extension of the specified filename by the given extension. If the filename has no extension, the specified one will be added.

Parameters:
filename - is the filename to parse.
extension - is the extension to remove if it is existing.
Returns:
the filename without the extension.

replaceExtension

public static URL replaceExtension(URL filename,
                                   String extension)
Replace the extension of the specified filename by the given extension. If the filename has no extension, the specified one will be added.

Parameters:
filename - is the filename to parse.
extension - is the extension to remove if it is existing.
Returns:
the filename without the extension.

addExtension

public static File addExtension(File filename,
                                String extension)
Add the extension of to specified filename. If the filename has already the given extension, the filename is not changed. If the filename has no extension or an other extension, the specified one is added.

Parameters:
filename - is the filename to parse.
extension - is the extension to remove if it is existing.
Returns:
the filename with the extension.
Since:
6.0

addExtension

public static URL addExtension(URL filename,
                               String extension)
Add the extension of to specified filename. If the filename has already the given extension, the filename is not changed. If the filename has no extension or an other extension, the specified one is added.

Parameters:
filename - is the filename to parse.
extension - is the extension to remove if it is existing.
Returns:
the filename with the extension.
Since:
6.0

delete

public static void delete(File file)
                   throws IOException
Delete the given directory and all its subdirectories. If the given file is a directory, its content and the file itself are recursivelly removed.

Parameters:
file - is the file to delete.
Throws:
IOException
Since:
6.0
See Also:
for the deletion on a file only., to create a directory., to create a directory and all its parents.

deleteOnExit

public static void deleteOnExit(File file)
                         throws IOException
Delete the given directory and all its subdirectories when the JVM is exiting. If the given file is a directory, its content and the file itself are recursivelly removed.

To cancel this action, see undeleteOnExit(File).

Parameters:
file - is the file to delete.
Throws:
IOException
Since:
6.0
See Also:
for the deletion on a file only., to create a directory., to create a directory and all its parents.

undeleteOnExit

public static void undeleteOnExit(File file)
                           throws IOException
Cancel the deletion of the given directory and all its subdirectories when the JVM is exiting.

Parameters:
file - is the file to undelete.
Throws:
IOException
Since:
6.0
See Also:
deleteOnExit(File), for the deletion on a file only., to create a directory., to create a directory and all its parents.

fileCopy

@Deprecated
public static void fileCopy(File in,
                                       File out)
                     throws IOException
Deprecated. copy(File, File)

Copy the first file into the second file.

The content of the second file will be lost. This copy function allows to do a copy between two different partitions.

Parameters:
in - is the file to copy.
out - is the target file
Throws:
IOException - in case of error.
See Also:
fileCopy(URL, File)

copy

public static void copy(File in,
                        File out)
                 throws IOException
Copy the first file into the second file.

The content of the second file will be lost. This copy function allows to do a copy between two different partitions.

If the out parameter is a directory, the output file is a file with the same basename as the input and inside the ou directory.

Parameters:
in - is the file to copy.
out - is the target file
Throws:
IOException - in case of error.
Since:
6.0
See Also:
copy(URL, File)

fileCopy

@Deprecated
public static void fileCopy(URL in,
                                       File out)
                     throws IOException
Deprecated. copy(URL, File)

Copy the first file into the second file.

The content of the second file will be lost. This copy function allows to do a copy between two different partitions.

Parameters:
in - is the file to copy.
out - is the target file
Throws:
IOException - in case of error.
See Also:
fileCopy(File, File)

copy

public static void copy(URL in,
                        File out)
                 throws IOException
Copy the first file into the second file.

The content of the second file will be lost. This copy function allows to do a copy between two different partitions.

Parameters:
in - is the file to copy.
out - is the target file
Throws:
IOException - in case of error.
Since:
6.0
See Also:
copy(File, File)

copy

public static void copy(InputStream in,
                        int inSize,
                        FileOutputStream out)
                 throws IOException
Copy the first file into the second file.

The content of the second file will be lost. This copy function allows to do a copy between two different partitions.

Parameters:
in - is the input stream to read.
inSize - is the total size of the input stream.
out - is the output stream.
Throws:
IOException
Since:
6.2

getUserHomeDirectory

public static File getUserHomeDirectory()
                                 throws FileNotFoundException
Replies the user home directory.

Returns:
the home directory of the current user.
Throws:
FileNotFoundException

getUserHomeDirectoryName

public static String getUserHomeDirectoryName()
Replies the user home directory.

Returns:
the home directory of the current user.

getUserConfigurationDirectoryFor

public static File getUserConfigurationDirectoryFor(String software)
Replies the user configuration directory for the specified software.

On Unix operating systems, the user directory for a software is by default $HOME/.software where software is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by default C:<span>\</span>Documents and Settings<span>\</span>userName<span>\</span>Local Settings<span>\</span>Application Data<span>\</span>software where userName is the login of the current user and software is the given parameter (case-insensitive).

Parameters:
software - is the name of the concerned software.
Returns:
the configuration directory of the software for the current user.

getUserConfigurationDirectoryNameFor

public static String getUserConfigurationDirectoryNameFor(String software)
Replies the user configuration directory for the specified software.

On Unix operating systems, the user directory for a software is by default $HOME/.software where software is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by default C:<span>\</span>Documents and Settings<span>\</span>userName<span>\</span>Local Settings<span>\</span>Application Data<span>\</span>software where userName is the login of the current user and software is the given parameter (case-insensitive).

Parameters:
software - is the name of the concerned software.
Returns:
the configuration directory of the software for the current user.

getSystemConfigurationDirectoryFor

public static File getSystemConfigurationDirectoryFor(String software)
Replies the system configuration directory for the specified software.

On Unix operating systems, the system directory for a software is by default /etc/software where software is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by default C:<span>\</span>Program Files<span>\</span>software where software is the given parameter (case-insensitive).

Parameters:
software - is the name of the concerned software.
Returns:
the configuration directory of the software for the current user.

getSystemConfigurationDirectoryNameFor

public static String getSystemConfigurationDirectoryNameFor(String software)
Replies the user configuration directory for the specified software.

On Unix operating systems, the system directory for a software is by default /etc/software where software is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by default C:<span>\</span>Program Files<span>\</span>software where software is the given parameter (case-insensitive).

Parameters:
software - is the name of the concerned software.
Returns:
the configuration directory of the software for the current user.

getSystemSharedLibraryDirectoryFor

public static File getSystemSharedLibraryDirectoryFor(String software)
Replies the system shared library directory for the specified software.

On Unix operating systems, the system directory for a software is by default /usr/lib/software where software is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by default C:<span>\</span>Program Files<span>\</span>software where software is the given parameter (case-insensitive).

Parameters:
software - is the name of the concerned software.
Returns:
the configuration directory of the software for the current user.

getSystemSharedLibraryDirectoryNameFor

public static String getSystemSharedLibraryDirectoryNameFor(String software)
Replies the system shared library directory for the specified software.

On Unix operating systems, the system directory for a software is by default /usr/lib/software where software is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by default C:<span>\</span>Program Files<span>\</span>software where software is the given parameter (case-insensitive).

Parameters:
software - is the name of the concerned software.
Returns:
the configuration directory of the software for the current user.

convertUrlToFile

@Deprecated
public static File convertUrlToFile(URL url)
Deprecated. convertURLToFile(URL)

Convert an URL which represents a local file into a File.

Parameters:
url - is the URL to convert.
Returns:
the file.
Throws:
IllegalArgumentException - is the URL was malformed.

convertURLToFile

public static File convertURLToFile(URL url)
Convert an URL which represents a local file into a File.

Parameters:
url - is the URL to convert.
Returns:
the file.
Throws:
IllegalArgumentException - is the URL was malformed.

convertStringToUrl

@Deprecated
public static URL convertStringToUrl(String urlDescription,
                                                boolean allowResourceSearch)
Deprecated. see convertStringToURL(String, boolean)

Convert a string to an URL according to several rules.

The rules are (the first succeeded is replied):

Parameters:
urlDescription - is a string which is describing an URL.
allowResourceSearch - indicates if the convertion must take into account the Java resources.
Returns:
the URL.
Throws:
IllegalArgumentException - is the string could not be formatted to URL.
See Also:
Resources.getResource(String)

convertStringToURL

public static URL convertStringToURL(String urlDescription,
                                     boolean allowResourceSearch)
Convert a string to an URL according to several rules.

The rules are (the first succeeded is replied):

Parameters:
urlDescription - is a string which is describing an URL.
allowResourceSearch - indicates if the convertion must take into account the Java resources.
Returns:
the URL.
Throws:
IllegalArgumentException - is the string could not be formatted to URL.
See Also:
Resources.getResource(String)

convertStringToUrl

@Deprecated
public static URL convertStringToUrl(String urlDescription,
                                                boolean allowResourceSearch,
                                                boolean repliesFileURL)
Deprecated. convertStringToURL(String, boolean, boolean)

Convert a string to an URL according to several rules.

The rules are (the first succeeded is replied):

Parameters:
urlDescription - is a string which is describing an URL.
allowResourceSearch - indicates if the convertion must take into account the Java resources.
repliesFileURL - indicates if urlDescription is allowed to be a filename.
Returns:
the URL.
Throws:
IllegalArgumentException - is the string could not be formatted to URL.
See Also:
Resources.getResource(String)

convertStringToURL

public static URL convertStringToURL(String urlDescription,
                                     boolean allowResourceSearch,
                                     boolean repliesFileURL)
Convert a string to an URL according to several rules.

The rules are (the first succeeded is replied):

Parameters:
urlDescription - is a string which is describing an URL.
allowResourceSearch - indicates if the convertion must take into account the Java resources.
repliesFileURL - indicates if urlDescription is allowed to be a filename.
Returns:
the URL.
Throws:
IllegalArgumentException - is the string could not be formatted to URL.
See Also:
Resources.getResource(String)

convertStringToURL

static URL convertStringToURL(String urlDescription,
                              boolean allowResourceSearch,
                              boolean repliesFileURL,
                              boolean supportWindowsPaths)
Convert a string to an URL according to several rules.

The rules are (the first succeeded is replied):

Parameters:
urlDescription - is a string which is describing an URL.
allowResourceSearch - indicates if the convertion must take into account the Java resources.
repliesFileURL - indicates if urlDescription is allowed to be a filename.
supportWindowsPaths - indicates if Windows paths should be treated in particular way.
Returns:
the URL.
Throws:
IllegalArgumentException - is the string could not be formatted to URL.
See Also:
Resources.getResource(String)

makeAbsolute

public static File makeAbsolute(File filename,
                                File current)
Make the given filename absolute from the given root if it is not already absolute.

filenamecurrentResult
null null null
null /myroot null
/path/to/file null /path/to/file
path/to/file null path/to/file
/path/to/file /myroot /path/to/file
path/to/file /myroot /myroot/path/to/file

Parameters:
filename - is the name to make absolute.
current - is the current directory which permits to make absolute.
Returns:
an absolute filename.

isFileBasedURL

@Deprecated
public static boolean isFileBasedURL(URL url)
Deprecated. see URISchemeType.isFileBasedScheme()

Replies if the given URL is using a protocol which could be map to files.

Parameters:
url -
Returns:
true if the given url is a "file", "http", "https", "ftp", "ssh", "jar" or "resource", otherwise false.

isFileBasedScheme

@Deprecated
public static boolean isFileBasedScheme(URISchemeType scheme)
Deprecated. see URISchemeType.isFileBasedScheme()

Replies if the given URL scheme is using a protocol which could be map to files.

Parameters:
scheme -
Returns:
true if the given scheme is a "file", "http", "https", "ftp", "ssh", "jar" or "resource", otherwise false.
Since:
5.0

makeAbsolute

public static URL makeAbsolute(URL filename,
                               File current)
Make the given filename absolute from the given root if it is not already absolute.

filenamecurrentResult
null null null
null /myroot null
file:/path/to/file null file:/path/to/file
file:path/to/file null file:path/to/file
file:/path/to/file /myroot file:/path/to/file
file:path/to/file /myroot file:/myroot/path/to/file
http://host.com/path/to/file null http://host.com/path/to/file
http://host.com/path/to/file /myroot http://host.com/path/to/file
ftp://host.com/path/to/file null ftp://host.com/path/to/file
ftp://host.com/path/to/file /myroot ftp://host.com/path/to/file
ssh://host.com/path/to/file null ssh://host.com/path/to/file
ssh://host.com/path/to/file /myroot ssh://host.com/path/to/file

Parameters:
filename - is the name to make absolute.
current - is the current directory which permits to make absolute.
Returns:
an absolute filename.

makeAbsolute

public static URL makeAbsolute(URL filename,
                               URL current)
Make the given filename absolute from the given root if it is not already absolute.

filenamecurrentResult
null null null
null file:/myroot null
null http://host.com/myroot null
file:path/to/file null file:path/to/file
file:path/to/file file:/myroot file:/myroot/path/to/file
file:path/to/file http://host.com/myroot http://host.com/myroot/path/to/file
file:/path/to/file null file:/path/to/file
file:/path/to/file file:/myroot file:/path/to/file
file:/path/to/file http://host.com/myroot file:/path/to/file
http://host2.com/path/to/file null http://host2.com/path/to/file
http://host2.com/path/to/file file:/myroot http://host2.com/path/to/file
http://host2.com/path/to/file http://host.com/myroot http://host2.com/path/to/file
ftp://host2.com/path/to/file null ftp://host2.com/path/to/file
ftp://host2.com/path/to/file file:/myroot ftp://host2.com/path/to/file
ftp://host2.com/path/to/file http://host.com/myroot ftp://host2.com/path/to/file

Parameters:
filename - is the name to make absolute.
current - is the current directory which permits to make absolute.
Returns:
an absolute filename.

makeAbsolute

public static URL makeAbsolute(File filename,
                               URL current)
Make the given filename absolute from the given root if it is not already absolute.

filenamecurrentResult
null null null
null file:/myroot null
null http://host.com/myroot null
path/to/file null file:path/to/file
path/to/file file:/myroot file:/myroot/path/to/file
path/to/file http://host.com/myroot http://host.com/myroot/path/to/file
/path/to/file null file:/path/to/file
/path/to/file file:/myroot file:/path/to/file
/path/to/file http://host.com/myroot file:/path/to/file

Parameters:
filename - is the name to make absolute.
current - is the current directory which permits to make absolute.
Returns:
an absolute filename.
Since:
5.0

getParentURL

public static URL getParentURL(URL url)
                        throws MalformedURLException
Replies the parent URL for the given URL.

Parameters:
url -
Returns:
the parent URL
Throws:
MalformedURLException

isWindowsNativeFilename

public static boolean isWindowsNativeFilename(String filename)
Replies if the given string contains a Windows® native long filename.

Long filenames (LFN), spelled "long file names" by Microsoft Corporation, are Microsoft's way of implementing filenames longer than the 8.3, or short-filename, naming scheme used in Microsoft DOS in their modern FAT and NTFS filesystems. Because these filenames can be longer than the 8.3 filename, they can be more descriptive. Another advantage of this scheme is that it allows for use of *nix files ending in (e.g. .jpeg, .tiff, .html, and .xhtml) rather than specialized shortened names (e.g. .jpg, .tif, .htm, .xht).

The long filename system allows a maximum length of 255 UTF-16 characters, including spaces and non-alphanumeric characters; excluding the following characters, which have special meaning within the command interpreter or the operating system kernel: \ / : * ? " < > |

Parameters:
filename -
Returns:
true if the given filename is a long filename, otherwise false
See Also:
normalizeWindowsNativeFilename(String)

normalizeWindowsNativeFilename

public static File normalizeWindowsNativeFilename(String filename)
Normalize the given string contains a Windows® native long filename and replies a Java-standard version.

Long filenames (LFN), spelled "long file names" by Microsoft Corporation, are Microsoft's way of implementing filenames longer than the 8.3, or short-filename, naming scheme used in Microsoft DOS in their modern FAT and NTFS filesystems. Because these filenames can be longer than the 8.3 filename, they can be more descriptive. Another advantage of this scheme is that it allows for use of *nix files ending in (e.g. .jpeg, .tiff, .html, and .xhtml) rather than specialized shortened names (e.g. .jpg, .tif, .htm, .xht).

The long filename system allows a maximum length of 255 UTF-16 characters, including spaces and non-alphanumeric characters; excluding the following characters, which have special meaning within the command interpreter or the operating system kernel: \ / : * ? " < > |

Parameters:
filename -
Returns:
the normalized path or null if not a windows native path.
See Also:
isWindowsNativeFilename(String)

convertFileToURL

public static URL convertFileToURL(File file)
Replies an URL for the given file and translate it into a resource URL if the given file is inside the classpath.

Parameters:
file - is the filename to translate.
Returns:
the URL which is corresponding to file, or null if the url cannot be computed.

toShortestURL

public static URL toShortestURL(URL url)
Replies an URL for the given url and translate it into a resource URL if the given file is inside the classpath.

Parameters:
url - is the URL to make shortest.
Returns:
the URL which is corresponding to file, or null if the url cannot be computed.
Since:
4.0

makeRelative

public static File makeRelative(File filenameToMakeRelative,
                                File rootPath)
                         throws IOException
Make the given filename relative to the given root path.

Parameters:
filenameToMakeRelative - is the name to make relative.
rootPath - is the root path from which the relative path will be set.
Returns:
a relative filename.
Throws:
IOException - when is is impossible to retreive canonical paths.

makeRelative

public static File makeRelative(File filenameToMakeRelative,
                                URL rootPath)
                         throws IOException
Make the given filename relative to the given root path.

Parameters:
filenameToMakeRelative - is the name to make relative.
rootPath - is the root path from which the relative path will be set.
Returns:
a relative filename.
Throws:
IOException - when is is impossible to retreive canonical paths.
Since:
6.0

makeRelative

public static File makeRelative(URL filenameToMakeRelative,
                                URL rootPath)
                         throws IOException
Make the given filename relative to the given root path.

Parameters:
filenameToMakeRelative - is the name to make relative.
rootPath - is the root path from which the relative path will be set.
Returns:
a relative filename.
Throws:
IOException - when is is impossible to retreive canonical paths.
Since:
6.0

makeCanonicalURL

public static URL makeCanonicalURL(URL url)

A canonical pathname is both absolute and unique. This method maps the pathname to its unique form. This typically involves removing redundant names such as "." and ".." from the pathname.

Parameters:
url - is the URL to make canonical
Returns:
the canonical form of the given URL.
Since:
6.0

zipFile

public static void zipFile(File input,
                           OutputStream output)
                    throws IOException
Create a zip file from the given input file. If the input file is a directory, the content of the directory is zipped. If the input file is a standard file, it is zipped.

Parameters:
input -
output -
Throws:
IOException
Since:
6.2

unzipFile

public static void unzipFile(InputStream input,
                             File output)
                      throws IOException
Unzip the given stream and write out the file in the output. If the input file is a directory, the content of the directory is zipped. If the input file is a standard file, it is zipped.

Parameters:
input -
output -
Throws:
IOException
Since:
6.2

zipFile

public static void zipFile(File input,
                           File output)
                    throws IOException
Create a zip file from the given input file.

Parameters:
input -
output -
Throws:
IOException
Since:
6.2

unzipFile

public static void unzipFile(File input,
                             File output)
                      throws IOException
Unzip a file into the output directory.

Parameters:
input -
output -
Throws:
IOException
Since:
6.2

createTempDirectory

public static File createTempDirectory(String prefix,
                                       String suffix)
                                throws IOException
Create an empty directory in the default temporary-file directory, using the given prefix and suffix to generate its name. Invoking this method is equivalent to invoking createTempDirectory(prefix, suffix, null).

Parameters:
prefix - is the prefix string to be used in generating the file's name; must be at least three characters long
suffix - is the suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used
Returns:
An abstract pathname denoting a newly-created empty file
Throws:
IllegalArgumentException - If the prefix argument contains fewer than three characters
IOException - If a file could not be created
SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not allow a file to be created
Since:
6.2

createTempDirectory

public static File createTempDirectory(String prefix,
                                       String suffix,
                                       File directory)
                                throws IOException
Creates a new empty directory in the specified directory, using the given prefix and suffix strings to generate its name. If this method returns successfully then it is guaranteed that:
  1. The directory denoted by the returned abstract pathname did not exist before this method was invoked, and
  2. Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine.

This method provides only part of a temporary-file facility. To arrange for a file created by this method to be deleted automatically, use the deleteOnExit(java.io.File) method.

The prefix argument must be at least three characters long. It is recommended that the prefix be a short, meaningful string such as "hjb" or "mail". The suffix argument may be null, in which case the suffix ".tmp" will be used.

To create the new directory, the prefix and the suffix may first be adjusted to fit the limitations of the underlying platform. If the prefix is too long then it will be truncated, but its first three characters will always be preserved. If the suffix is too long then it too will be truncated, but if it begins with a period character ('.') then the period and the first three characters following it will always be preserved. Once these adjustments have been made the name of the new file will be generated by concatenating the prefix, five or more internally-generated characters, and the suffix.

If the directory argument is null then the system-dependent default temporary-file directory will be used. The default temporary-file directory is specified by the system property java.io.tmpdir. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "C:\\WINNT\\TEMP". A different value may be given to this system property when the Java virtual machine is invoked, but programmatic changes to this property are not guaranteed to have any effect upon the temporary directory used by this method.

Parameters:
prefix - is the prefix string to be used in generating the file's name; must be at least three characters long
suffix - is the suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used
directory - is the directory in which the file is to be created, or null if the default temporary-file directory is to be used
Returns:
An abstract pathname denoting a newly-created empty file
Throws:
IllegalArgumentException - If the prefix argument contains fewer than three characters
IOException - If a file could not be created
SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not allow a file to be created
Since:
6.2


Copyright © 2006-2011 Arakhnê.org Consortium. All rights reserved under LGPL license terms.