- java.lang.Object
-
- org.arakhne.afc.vmutil.FileSystem
-
public final class FileSystem extends Object
An utility class that permits to deal with filenames.- Version:
- 17.0 2020-01-04 14:41:35
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- vmutils
-
-
Field Summary
Fields Modifier and Type Field Description 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
UNIX_SEPARATOR_STRING
Character that is used for separating components of a path on Unix operating systems.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.static char
WINDOWS_SEPARATOR_CHAR
Character that is used for separating components of a path on Windows operating systems.static String
WINDOWS_SEPARATOR_STRING
Character that is used for separating components of a path on Windows operating systems.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 File
convertStringToFile(String filename)
Convert a string which represents a local file into a File.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)
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)
Convert an URL which represents a local file or a resource 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(String 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(String filename)
Reply all the extensions of the specified file.static String[]
extensions(URL filename)
Reply all the extensions of the specified 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(String 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
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)
Make the given URL canonical.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.
-
-
-
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
-
WINDOWS_SEPARATOR_CHAR
public static final char WINDOWS_SEPARATOR_CHAR
Character that is used for separating components of a path on Windows operating systems.- See Also:
- Constant Field Values
-
WINDOWS_SEPARATOR_STRING
public static final String WINDOWS_SEPARATOR_STRING
Character that is used for separating components of a path on Windows operating systems.- See Also:
- Constant Field Values
-
UNIX_SEPARATOR_STRING
public static final String UNIX_SEPARATOR_STRING
Character that is used for separating components of a path on Unix operating systems.- See Also:
- Constant Field Values
-
-
Method Detail
-
isJarURL
@Pure public static boolean isJarURL(URL url)
Replies if the given URL has a jar scheme.- Parameters:
url
- the URL to test.- Returns:
true
if the given URL uses a jar scheme.
-
getJarURL
@Pure public static URL getJarURL(URL url)
Replies the jar part of the jar-scheme URL.If the input URL is
jar:file:/path1/archive.jar!/path2/file
, the output of this function isfile:/path1/archive.jar
.- Parameters:
url
- the URL to test.- Returns:
- the URL of the jar file in the given URL, or
null
if the given URL does not use jar scheme.
-
getJarFile
@Pure public static File getJarFile(URL url)
Replies the file part of the jar-scheme URL.If the input URL is
jar:file:/path1/archive.jar!/path2/file
, the output of this function is/path2/file
.- Parameters:
url
- the URL to test.- Returns:
- the file in the given URL, or
null
if the given URL does not use jar scheme.
-
toJarURL
@Pure public static URL toJarURL(File jarFile, File insideFile) throws MalformedURLException
Replies the jar-schemed URL composed of the two given components.If the inputs are
/path1/archive.jar
and @{code /path2/file}, the output of this function isjar:file:/path1/archive.jar!/path2/file
.- 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
@Pure public static URL toJarURL(File jarFile, String insideFile) throws MalformedURLException
Replies the jar-schemed URL composed of the two given components.If the inputs are
/path1/archive.jar
and @{code /path2/file}, the output of this function isjar:file:/path1/archive.jar!/path2/file
.- 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
@Pure public static URL toJarURL(URL jarFile, File insideFile) throws MalformedURLException
Replies the jar-schemed URL composed of the two given components.If the inputs are
file:/path1/archive.jar
and @{code /path2/file}, the output of this function isjar:file:/path1/archive.jar!/path2/file
.- 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
@Pure public static URL toJarURL(URL jarFile, String insideFile) throws MalformedURLException
Replies the jar-schemed URL composed of the two given components.If the inputs are
file:/path1/archive.jar
and @{code /path2/file}, the output of this function isjar:file:/path1/archive.jar!/path2/file
.- 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
@Pure 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, otherwisefalse
-
getFileExtensionCharacter
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure public static String extension(String filename)
Reply the extension of the specified file.- Parameters:
filename
- is the name to parse.- Returns:
- the extension of the specified file
- Since:
- 7.0
- See Also:
shortBasename(File)
,largeBasename(File)
,basename(File)
,dirname(File)
,extensions(File)
-
extension
@Pure 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
@Pure 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
@Pure public static String[] extensions(String filename)
Reply all the extensions of the specified file.- Parameters:
filename
- is the name to parse.- Returns:
- the extensions of the specified file
- Since:
- 7.0
-
extensions
@Pure 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
@Pure 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
@Pure public static String[] split(URL filename)
Replies the parts of a path.If the input is
"http://www.arakhne.org/path/to/file.x.z.z"
, the replied paths are:""
,"path"
,"to"
, and"file.x.z.z"
.If the input is
"jar:file:/path1/archive.jar!/path2/file"
, the replied paths are:""
,"path2"
, and"file"
.- Parameters:
filename
- is the name to parse.- Returns:
- the parts of a path.
-
join
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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 parseextension
- is the extension to test.- Returns:
true
if the given filename has the given extension, otherwisefalse
-
hasExtension
@Pure public static boolean hasExtension(String 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 parseextension
- is the extension to test.- Returns:
true
if the given filename has the given extension, otherwisefalse
- Since:
- 7.0
-
hasExtension
@Pure 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 parseextension
- is the extension to test.- Returns:
true
if the given filename has the given extension, otherwisefalse
-
removeExtension
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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 givenfile
is a directory, its content and thefile
itself are recursivelly removed.- Parameters:
file
- is the file to delete.- Throws:
IOException
- when IO error occurs- 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 givenfile
is a directory, its content and thefile
itself are recursivelly removed.To cancel this action, see
undeleteOnExit(File)
.- Parameters:
file
- is the file to delete.- Throws:
IOException
- when cannot register the hook.- 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
- when the file cannot be registered.- 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.
-
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 theout
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)
-
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
- when copy error occurs.- Since:
- 6.2
-
getUserHomeDirectory
@Pure public static File getUserHomeDirectory() throws FileNotFoundException
Replies the user home directory.- Returns:
- the home directory of the current user.
- Throws:
FileNotFoundException
- when the home directory does not exist.
-
getUserHomeDirectoryName
@Pure public static String getUserHomeDirectoryName()
Replies the user home directory.- Returns:
- the home directory of the current user.
-
getUserConfigurationDirectoryFor
@Pure 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
wheresoftware
is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by defaultC:<span>\</span>Documents and Settings<span>\</span>userName<span>\</span>Local Settings<span>\</span> Application Data<span>\</span>software
whereuserName
is the login of the current user andsoftware
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
@Pure 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
wheresoftware
is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by defaultC:<span>\</span>Documents and Settings<span>\</span>userName<span>\</span>Local Settings<span>\</span> Application Data<span>\</span>software
whereuserName
is the login of the current user andsoftware
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
@Pure 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
wheresoftware
is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by defaultC:<span>\</span>Program Files<span>\</span>software
wheresoftware
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
@Pure 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
wheresoftware
is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by defaultC:<span>\</span>Program Files<span>\</span>software
wheresoftware
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
@Pure 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
wheresoftware
is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by defaultC:<span>\</span>Program Files<span>\</span>software
wheresoftware
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
@Pure 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
wheresoftware
is the given parameter (case-sensitive). On Windows® operating systems, the user directory for a software is by defaultC:<span>\</span>Program Files<span>\</span>software
wheresoftware
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.
-
convertStringToFile
@Pure public static File convertStringToFile(String filename)
Convert a string which represents a local file into a File.This function supports the naming standards coming for the different operating systems.
- Parameters:
filename
- the filename.- Returns:
- the file, or
null
if the given filename isnull
or empty. - Since:
- 13.0
-
convertURLToFile
@Pure public static File convertURLToFile(URL url)
Convert an URL which represents a local file or a resource into a File.- Parameters:
url
- is the URL to convert.- Returns:
- the file.
- Throws:
IllegalArgumentException
- is the URL was malformed.
-
convertStringToURL
@Pure 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):
- if
urlDescription
isnull
or empty, returnnull
; - try to build an
URL
withurlDescription
as parameter; - if
allowResourceSearch
istrue
andurlDescription
starts with"resource:"
, callResources.getResource(String)
with the rest of the string as parameter; - if
allowResourceSearch
istrue
, callResources.getResource(String)
with theurlDescription
as parameter; - assuming that the
urlDescription
is a filename, callFile.toURI()
to retreive an URI and thenURI.toURL()
; - If everything else failed, return
null
.
- 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)
- if
-
convertStringToURL
@Pure 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):
- if
urlDescription
isnull
or empty, returnnull
; - try to build an
URL
withurlDescription
as parameter; - if
allowResourceSearch
istrue
andurlDescription
starts with"resource:"
, callResources.getResource(String)
with the rest of the string as parameter; - if
allowResourceSearch
istrue
, callResources.getResource(String)
with theurlDescription
as parameter; - if
repliesFileURL
istrue
and assuming that theurlDescription
is a filename, callFile.toURI()
to retreive an URI and thenURI.toURL()
; - If everything else failed, return
null
.
- 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)
- if
-
convertStringToURL
@Pure 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):
- if
urlDescription
isnull
or empty, returnnull
; - try to build an
URL
withurlDescription
as parameter; - if
allowResourceSearch
istrue
andurlDescription
starts with"resource:"
, callResources.getResource(String)
with the rest of the string as parameter; - if
allowResourceSearch
istrue
, callResources.getResource(String)
with theurlDescription
as parameter; - if
repliesFileURL
istrue
and assuming that theurlDescription
is a filename, callFile.toURI()
to retreive an URI and thenURI.toURL()
; - If everything else failed, return
null
.
- 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)
- if
-
makeAbsolute
@Pure public static File makeAbsolute(File filename, File current)
Make the given filename absolute from the given root if it is not already absolute.filename
current
Result 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.
-
makeAbsolute
@Pure public static URL makeAbsolute(URL filename, File current)
Make the given filename absolute from the given root if it is not already absolute.filename
current
Result 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
@Pure public static URL makeAbsolute(URL filename, URL current)
Make the given filename absolute from the given root if it is not already absolute.filename
current
Result 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
@Pure public static URL makeAbsolute(File filename, URL current)
Make the given filename absolute from the given root if it is not already absolute.filename
current
Result 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
@Pure public static URL getParentURL(URL url) throws MalformedURLException
Replies the parent URL for the given URL.- Parameters:
url
- the URL.- Returns:
- the parent URL
- Throws:
MalformedURLException
- if the parent URL cannot be built.
-
isWindowsNativeFilename
@Pure 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
- the filename to test.- Returns:
true
if the given filename is a long filename, otherwisefalse
- See Also:
normalizeWindowsNativeFilename(String)
-
normalizeWindowsNativeFilename
@Pure 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
- the filename to test.- Returns:
- the normalized path or
null
if not a windows native path. - See Also:
isWindowsNativeFilename(String)
-
convertFileToURL
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure 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
@Pure public static URL makeCanonicalURL(URL url)
Make the given URL canonical.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, File output) throws IOException
Create a zip file from the given input file.- Parameters:
input
- the name of the file to compress.output
- the name of the ZIP file to create.- Throws:
IOException
- when ziiping is failing.- Since:
- 6.2
-
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
- the name of the file to compress.output
- the name of the ZIP file to create.- Throws:
IOException
- when ziiping is failing.- 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
- the ZIP file to uncompress.output
- the uncompressed file to create.- Throws:
IOException
- when uncompressing is failing.- Since:
- 6.2
-
unzipFile
public static void unzipFile(File input, File output) throws IOException
Unzip a file into the output directory.- Parameters:
input
- the ZIP file to uncompress.output
- the uncompressed file to create.- Throws:
IOException
- when uncompressing is failing.- 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 longsuffix
- is the suffix string to be used in generating the file's name; may benull
, in which case the suffix".tmp"
will be used- Returns:
- An abstract pathname denoting a newly-created empty file
- Throws:
IllegalArgumentException
- If theprefix
argument contains fewer than three charactersIOException
- If a file could not be createdSecurityException
- If a security manager exists and its
method does not allow a file to be createdSecurityManager.checkWrite(java.lang.String)
- 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:- The directory denoted by the returned abstract pathname did not exist before this method was invoked, and
- 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
method.deleteOnExit(java.io.File)
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"
. Thesuffix
argument may benull
, 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 isnull
then the system-dependent default temporary-file directory will be used. The default temporary-file directory is specified by the system propertyjava.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 longsuffix
- is the suffix string to be used in generating the file's name; may benull
, in which case the suffix".tmp"
will be useddirectory
- is the directory in which the file is to be created, ornull
if the default temporary-file directory is to be used- Returns:
- An abstract pathname denoting a newly-created empty file
- Throws:
IllegalArgumentException
- If theprefix
argument contains fewer than three charactersIOException
- If a file could not be createdSecurityException
- If a security manager exists and its
method does not allow a file to be createdSecurityManager.checkWrite(java.lang.String)
- Since:
- 6.2
-
-