public class FileUtilities extends Object
Modifier and Type | Field and Description |
---|---|
static String |
FIREFOX10_USERAGENT
The Firefox 10 user agent.
|
static String |
IE9_USERAGENT
The IE9 user agent.
|
static int |
OPTION_ACCEPT301CODE
The option used if 301 or 308 return codes will be accepted as valid responses (URL found).
|
static short |
OPTION_CHILDURL_DEFAULT
The default option for the
getChildURL(java.net.URL, java.lang.String, int) . |
static short |
OPTION_CHILDURL_ESCAPE
The option for the
getChildURL(java.net.URL, java.lang.String, int) to escape the result. |
static short |
OPTION_CHILDURL_FILTEREXIST
The option for the
getChildURL(java.net.URL, java.lang.String, int) to check if the resulting file exists. |
static short |
OPTION_CHILDURL_FILTEREXIST_FILE
The option for the
getChildURL(java.net.URL, java.lang.String, int) to check if the resulting file exists only for file protocols. |
static short |
OPTION_CHILDURL_FILTEREXIST_HTTP
The option for the
getChildURL(java.net.URL, java.lang.String, int) to check if the resulting file exists only for http and https protocols. |
static short |
OPTION_FILEEXIST_DEFAULT
The default option for the
exist(java.io.File, short) and exist(java.net.URL, short) . |
static short |
OPTION_FILEEXIST_HTTP_FORCETRUE
The option for the
exist(java.io.File, short) and exist(java.net.URL, short) by setting by default that http resources exists. |
static short |
OPTION_FILEEXIST_LENGTH
The option for the
exist(java.io.File, short) and exist(java.net.URL, short) by getting the file length to check the file existence. |
static short |
OPTION_FILEEXIST_READ
The option for the
exist(java.io.File, short) and exist(java.net.URL, short) by trying to read the beginning of the file to check the
file existence. |
static short |
OPTION_FILEEXIST_SKIP_PHP
The option for the
exist(java.io.File, short) and exist(java.net.URL, short) by considering that URLs which point to php resources don't
exist. |
static short |
OPTION_FILEEXIST_SKIP_QUERIES
The option for the
exist(java.io.File, short) and exist(java.net.URL, short) by considering that URLs with queries don't exist. |
static int |
OPTION_FOLLOWREDIRECT
The option used if redirection links will be followed and used to check that the links exists.
|
Modifier | Constructor and Description |
---|---|
protected |
FileUtilities() |
Modifier and Type | Method and Description |
---|---|
static boolean |
checkFilePermissions()
Return true if the application has the right to get Files in the local network.
|
static URL |
collapse(URL url)
Collapse an URL to a representation without any
.. |
static File |
createFile(File dir,
String path)
Create the File whose name is defined by path, and which may be defined relative to a parent directory.
|
static String |
encodeURL(String path)
Filter a path name for an URL, replacing spaces characters by their percent encoding equivalent.
|
static boolean |
exist(File file)
Return true if the file or the resource denoted by this URL exist.
|
static boolean |
exist(File file,
int option)
Return true if the file or the resource denoted by this URL exist.
|
static boolean |
exist(File file,
short option)
Return true if the file or the resource denoted by this URL exist.
|
static boolean |
exist(URL url)
Return true if the URL or the resource denoted by this URL exist.
|
static boolean |
exist(URL url,
int option)
Return true if the file or the resource denoted by this URL exist.
|
static boolean |
exist(URL url,
short option)
Return true if the file or the resource denoted by this URL exist.
|
static URL |
fixURLPath(URL url)
Filter a path name for an URL, replacing spaces characters by their percent encoding equivalent.
|
static File |
getAbsoluteFile(File baseDir,
String relativePath)
Return the File corresponding to a String-defined path, that can be defined as absolute, or as relative to a base directory.
|
static String |
getAbsolutePath(File baseDir,
String path)
Return the absolute path of an URL, using the file separator of the platform.
|
static String |
getAbsolutePath(File baseDir,
String path,
boolean filterExistingURLs)
Return the absolute path of an URL, using the file separator of the platform.
|
static String |
getAbsolutePath(URL baseURL,
String relativePath)
Return the absolute path of an URL, using the file separator of the platform.
|
static URL |
getAbsoluteURL(URL baseURL,
String relativePath)
Return the File corresponding to a String-defined path, that can be defined as absolute, or as relative to a base directory.
|
static List<URL> |
getChildren(URL url,
boolean strict)
Return the list of children of a URL designing a directory, including directories in jar or zip files.
|
static URL |
getChildURL(URL parentURL,
String path)
Return an URL by its relative path from a parent URL.
|
static URL |
getChildURL(URL parentURL,
String path,
boolean filterExistingURLs)
Return an URL by its relative path from a parent URL.
|
static URL |
getChildURL(URL parentURL,
String path,
boolean filterExistingURLs,
boolean escape)
Return an URL by its relative path from a parent URL.
|
static URL |
getChildURL(URL parentURL,
String path,
int options)
Return an URL by its relative path from a parent URL.
|
static File |
getCompatibleFile(File file,
Set<String> extensions,
String defaultExt)
Return a File abstract representation, making sure that it have one of the desired extensions.
|
static File |
getCompatibleFile(File file,
String ext)
Return a File abstract representation, making sure that it have the desired extension.
|
static File |
getCompatibleFile(File file,
String[] exts)
Return a File abstract representation, making sure that it have the desired extension.
|
static File |
getCompatibleFile(File file,
String[] exts,
String defaultExt)
Return a File abstract representation, making sure that it have the desired extension.
|
static File |
getDirectory(String path)
Get the directory whose name is defined by path.
|
static String |
getDrive(File file)
Return the drive name of a file.
|
static String |
getEscapedName(String name)
Return a name without blank, and containing only ASCII characters.
|
static File |
getFile(File dir,
String path)
Return the File whose name is defined by path.This method will return null if one of these conditions is true:
path is null
path does not define an existing file path
|
static File |
getFile(File dir,
String path,
boolean filterExisting)
Return the File whose name is defined by path.This method will return null if one of these conditions is true:
path is null
path does not define an existing file path if
filterExisting is true
|
static File |
getFile(String path)
Return the File whose name is defined by path.
|
static File |
getFile(String path,
boolean filterExisting)
Return the File whose name is defined by path.
|
static File |
getFile(URL url)
Return a File for an URL, replacing percent encoding characters by their equivalent characters.
|
static String |
getFileExtension(File file)
Return the extension of a File.
|
static String |
getFileExtension(URL url)
Return the extension of a URL.
|
static String |
getFileName(File file)
Return the file name without the path, nor the extension.
|
static String |
getFileName(URL url)
Return the URL name without the path, nor the extension.
|
static String |
getFileNameBody(File file)
Return the body name of a File (before the extension if there is an extension, else this is the name of the file itself).
|
static String |
getFileNameBody(URL url)
Return the body name of a URL (before the extension if there is an extension, else this is the name of the file itself).
|
static String |
getFileNameWithExtension(File file)
Return the file name without the path, but keeping the extension.
|
static String |
getFileNameWithExtension(URL url)
Return the URL name without the path, but keeping the extension.
|
static File[] |
getFilesFromURLList(List<URL> list)
Return a list of Files defined by their list of URLs.
|
static File[] |
getFilesFromURLList(List<URL> list,
boolean filterExistingURLs)
Return a list of Files defined by their list of URLs.
|
static URL |
getJarEntryURL(URL url,
String entryPath)
Return an URL corresponding to an entry in a Jar file.
|
static URL |
getJarEntryURL(URL url,
String entryPath,
URLStreamHandler handler)
Return an URL corresponding to an entry in a Jar file.
|
static URL |
getParentURL(URL url)
Return the parent URL of a given URL.
|
static URL |
getParentURL(URL url,
boolean endSeparator)
Return the parent URL of a given URL.
|
static URL |
getProtectedURL(File file)
Return the URL corresponding to a File, avoiding to throw a SecurityException in secured environments like Applets.
|
static URL |
getRedirectURL(URL url)
Return the final URL after applying all the possible redirections.
|
static String |
getRelativePath(File baseDir,
File file)
Return the path of a File relative to a directory.
|
static String |
getRelativePath(File baseDir,
File file,
boolean strict)
Return the path of a File relative to a directory.
|
static String |
getRelativePath(URL baseURL,
URL url)
Return the path of an URL relative to a directory.
|
static String |
getRelativePath(URL baseURL,
URL url,
boolean strict)
Return the path of an URL relative to a directory.
|
static int |
getResponseCode(URL url)
Return the response code for an URL, without a proxy.
|
static int |
getResponseCode(URL url,
int timeOut)
Return the response code for an URL, without a proxy.
|
static int |
getResponseCode(URL url,
Proxy proxy)
Return the response code for an URL, without using a timeOut.
|
static int |
getResponseCode(URL url,
Proxy proxy,
int timeOut)
Return the response code for an URL.
|
static int |
getResponseCode(URL url,
Proxy proxy,
String userAgent)
Return the response code for an URL, witbout using a timeOut.
|
static int |
getResponseCode(URL url,
Proxy proxy,
String userAgent,
int timeOut)
Return the response code for an URL.
|
static Set<String> |
getRootNames()
Return the file system root names.
|
static String |
getText(File file)
Return the text corresponding to a File.
|
static String |
getText(URL url)
Return the text corresponding to a URL.
|
static URL |
getURL(File baseDir,
String path)
Return the URL whose name is defined by path.
|
static URL |
getURL(File baseDir,
String path,
boolean filterExistingURLs)
Return the URL whose name is defined by path.
|
static List<URL> |
getURLListFromFiles(File[] files)
Return a list of URLs defined by their list of Files.
|
static List<URL> |
getURLListFromFiles(File[] files,
boolean filterExistingFiles)
Return a list of URLs defined by their list of Files.
|
static URL[] |
getURLs(File dir,
String paths)
Return a list of URLs from a String.
|
static URL[] |
getURLs(File dir,
String paths,
boolean filterExistingURLs)
Return a list of URLs from a String.
|
static List<URL> |
getURLsFromString(File baseDir,
String urlList)
Return a List of URLs from a String separated with a ";".
|
static List<URL> |
getURLsFromString(File baseDir,
String urlList,
boolean filterExistingURLs)
Return a List of URLs from a String separated with a ";".
|
static List<URL> |
getURLsFromString(URL baseDir,
String urlList)
Return a List of URLs from a String separated with a ";".
|
static List<URL> |
getURLsFromString(URL baseDir,
String urlList,
boolean filterExistingURLs)
Return a List of URLs from a String separated with a ";".
|
static boolean |
isAbsolute(String path)
Return true if a path is absolute.
|
static boolean |
isAbsoluteURI(String path)
Return true if an URI path is absolute.
|
static boolean |
isAncestor(File ancestor,
File file)
Return true if a file is an ancestor of another file.
|
static boolean |
isAncestor(URL ancestor,
URL url)
Return true if an URL is an ancestor of another URL.
|
static boolean |
isArchive(File f)
Return true if a File is an archive.
|
static boolean |
isArchive(URL url)
Return true if an url is an archive.
|
static boolean |
isDirectory(URL url)
Return true if an URL correspond to a directory, including directories in jar or zip files.
|
static boolean |
isFileOrHTTPProtocol(URL url)
Return true if the protocol is a file, http, or https protocol.
|
static boolean |
isHTTPProtocol(String path)
Return true if the protocol is a http, or https protocol.
|
static boolean |
isHTTPProtocol(URL url)
Return true if the protocol is a http, or https protocol.
|
static boolean |
isHTTPSProtocol(String path)
Return true if the protocol is a https protocol.
|
static boolean |
isHTTPSProtocol(URL url)
Return true if the protocol is a https protocol.
|
static boolean |
isRelativeTo(File baseDir,
File file)
Return true if a file is relative to a directory (that is: the directory is one of the file ancestors).
|
static boolean |
isRoot(File dir)
Return true if a directory is a root of the file system.
|
static boolean |
isURLFound(URL url)
Return true if an URL is found, without using a timeOut.
|
static boolean |
isURLFound(URL url,
int options)
Return true if an URL is found, without using a timeOut.
|
static boolean |
isURLFound(URL url,
int options,
int timeOut)
Return true if an URL is found.
|
static boolean |
isURLFound(URL url,
Proxy proxy)
Return true if an URL is found, without using a timeOut.
|
static boolean |
isURLFound(URL url,
Proxy proxy,
int timeOut)
Return true if an URL is found.
|
static boolean |
isURLFound(URL url,
Proxy proxy,
int options,
int timeOut)
Return true if an URL is found.
|
static boolean |
isURLFound(URL url,
Proxy proxy,
String userAgent)
Return true if an URL is found, without using a timeOut.
|
static boolean |
isURLFound(URL url,
Proxy proxy,
String userAgent,
int timeOut)
Return true if an URL is found.
|
static boolean |
isURLFound(URL url,
Proxy proxy,
String userAgent,
int options,
int timeOut)
Return true if an URL is found.
|
static URL |
makeAbsoluteURLPath(String path)
Create an URL from a path, removing the relative delimiters.
|
static URL |
normalize(URL url)
Normalize an URL by removing "." and ".." in the path part of the URL.
|
static String |
replaceEscapedSequences(String path)
Replace the percent-encoding escape sequences in a URL path by their equivalent characters.
|
static String |
replaceEscapedSequences(String path,
boolean keepEscapedSpaces)
Replace the percent-encoding escape sequences in a URL path by their equivalent characters.
|
static boolean |
sameURL(URL url1,
URL url2)
Check if two URLs are the same, taking into account double slash and .. constructs.
|
static boolean |
useFileOrHTTPProtocol(String url)
Return true if the URL use a file, http, or https protocol.
|
static boolean |
useFileProtocol(String url)
Return true if the URL use the file protocol.
|
static boolean |
useHTTPProtocol(String url)
Return true if the URL use a http, or https protocol.
|
public static final int OPTION_ACCEPT301CODE
public static final int OPTION_FOLLOWREDIRECT
public static final short OPTION_FILEEXIST_DEFAULT
exist(java.io.File, short)
and exist(java.net.URL, short)
.public static final short OPTION_FILEEXIST_READ
exist(java.io.File, short)
and exist(java.net.URL, short)
by trying to read the beginning of the file to check the
file existence.public static final short OPTION_FILEEXIST_LENGTH
exist(java.io.File, short)
and exist(java.net.URL, short)
by getting the file length to check the file existence.public static final short OPTION_FILEEXIST_SKIP_QUERIES
exist(java.io.File, short)
and exist(java.net.URL, short)
by considering that URLs with queries don't exist.public static final short OPTION_FILEEXIST_SKIP_PHP
exist(java.io.File, short)
and exist(java.net.URL, short)
by considering that URLs which point to php resources don't
exist.public static final short OPTION_FILEEXIST_HTTP_FORCETRUE
exist(java.io.File, short)
and exist(java.net.URL, short)
by setting by default that http resources exists.public static final short OPTION_CHILDURL_DEFAULT
getChildURL(java.net.URL, java.lang.String, int)
.public static final short OPTION_CHILDURL_ESCAPE
getChildURL(java.net.URL, java.lang.String, int)
to escape the result.public static final short OPTION_CHILDURL_FILTEREXIST
getChildURL(java.net.URL, java.lang.String, int)
to check if the resulting file exists.public static final short OPTION_CHILDURL_FILTEREXIST_FILE
getChildURL(java.net.URL, java.lang.String, int)
to check if the resulting file exists only for file protocols.public static final short OPTION_CHILDURL_FILTEREXIST_HTTP
getChildURL(java.net.URL, java.lang.String, int)
to check if the resulting file exists only for http and https protocols.public static final String FIREFOX10_USERAGENT
public static final String IE9_USERAGENT
public static Set<String> getRootNames()
public static boolean useFileOrHTTPProtocol(String url)
url
- the URLpublic static boolean useFileProtocol(String url)
url
- the URLpublic static boolean useHTTPProtocol(String url)
url
- the URLpublic static boolean isFileOrHTTPProtocol(URL url)
url
- the URLpublic static boolean isHTTPSProtocol(URL url)
url
- the URLpublic static boolean isHTTPProtocol(URL url)
url
- the URLpublic static boolean isHTTPSProtocol(String path)
path
- the pathpublic static boolean isHTTPProtocol(String path)
path
- the pathpublic static boolean checkFilePermissions()
public static boolean exist(URL url)
exist(java.net.URL, short)
with the OPTION_FILEEXIST_READ
option.url
- the URLpublic static boolean exist(URL url, short option)
url
- the URLoption
- the option to detected if the file exist. The following optinos are available:
OPTION_FILEEXIST_READ
: by trying to read the beginning of the fileOPTION_FILEEXIST_LENGTH
: by getting a not null length for the fileOPTION_FILEEXIST_SKIP_QUERIES
: by considering that URL with queries don't existOPTION_FILEEXIST_SKIP_PHP
: by considering that URL which point to php resources don't existOPTION_FILEEXIST_HTTP_FORCETRUE
: by considering that URL which point to http or https resources exist (if queries or php resources areot
skipped)public static boolean exist(URL url, int option)
url
- the URLoption
- the option to detected if the file exist. The following optinos are available:
OPTION_FILEEXIST_READ
: by trying to read the beginning of the fileOPTION_FILEEXIST_LENGTH
: by getting a not null length for the fileOPTION_FILEEXIST_SKIP_QUERIES
: by considering that URL with queries don't existOPTION_FILEEXIST_SKIP_PHP
: by considering that URL which point to php resources don't existOPTION_FILEEXIST_HTTP_FORCETRUE
: by considering that URL which point to http or https resources exist (if queries or php resources areot
skipped)public static boolean exist(File file)
exist(java.io.File, short)
with the OPTION_FILEEXIST_READ
option.file
- the filepublic static boolean exist(File file, short option)
file
- the fileoption
- the option to detected if the file exist. The following options are available:
OPTION_FILEEXIST_READ
: by trying to read the beginning of the fileOPTION_FILEEXIST_LENGTH
: by getting a not null length for the filepublic static boolean exist(File file, int option)
file
- the fileoption
- the option to detected if the file exist. The following options are available:
OPTION_FILEEXIST_READ
: by trying to read the beginning of the fileOPTION_FILEEXIST_LENGTH
: by getting a not null length for the filepublic static URL getJarEntryURL(URL url, String entryPath) throws MalformedURLException
url
- the parent URLentryPath
- the path of the child relative to the parentMalformedURLException
- if the resulting URL is invalid, or the protocol is not file:public static URL getJarEntryURL(URL url, String entryPath, URLStreamHandler handler) throws MalformedURLException
url
- the parent URLentryPath
- the path of the child relative to the parenthandler
- the URLStreamHandlerMalformedURLException
- if the resulting URL is invalid, or the protocol is not file:public static URL getChildURL(URL parentURL, String path, int options)
parentURL
- the parent URLpath
- the path of the child relative to the parentoptions
- the options. The following options are available:
OPTION_CHILDURL_ESCAPE
: if space characters will be escapedOPTION_CHILDURL_FILTEREXIST
: if not existing resources will be filteredOPTION_CHILDURL_FILTEREXIST_FILE
: if not existing non http resources will be filteredOPTION_CHILDURL_FILTEREXIST_HTTP
: if not existing http resources will be filteredpublic static URL getChildURL(URL parentURL, String path)
parentURL
- the parent URLpath
- the path of the child relative to the parentpublic static URL getChildURL(URL parentURL, String path, boolean filterExistingURLs)
parentURL
- the parent URLpath
- the path of the child relative to the parentfilterExistingURLs
- if true, return true if the resulting URL does not existpublic static URL getChildURL(URL parentURL, String path, boolean filterExistingURLs, boolean escape)
parentURL
- the parent URLpath
- the path of the child relative to the parentfilterExistingURLs
- if true, return true if the resulting URL does not existescape
- true if spaces in file paths must be escaped by a "%20" Stringpublic static URL getParentURL(URL url)
url
- the URLpublic static URL getParentURL(URL url, boolean endSeparator)
url
- the URLendSeparator
- true if an end separator ("/") must be added at the end of the parent pathpublic static URL normalize(URL url)
URI.normalize()
method does not normalize
some URIs. This method will never throw a MalformedURLException
but instead return the initial URL in this case.url
- the URLpublic static File getDirectory(String path)
path
- the pathpublic static String getFileNameBody(File file)
file
- the Filepublic static String getFileNameBody(URL url)
url
- the URLpublic static String getFileName(File file)
file
- the Filepublic static URL fixURLPath(URL url)
url
- the urlpublic static String encodeURL(String path)
path
- the pathpublic static String replaceEscapedSequences(String path, boolean keepEscapedSpaces)
path
- the pathkeepEscapedSpaces
- allow to keep the escaping of spaces (%20)public static String replaceEscapedSequences(String path)
path
- the pathpublic static String getFileNameWithExtension(File file)
file
- the Filepublic static String getFileNameWithExtension(URL url)
url
- the URLpublic static String getFileName(URL url)
url
- the URLpublic static String getFileExtension(File file)
file
- the Filepublic static String getFileExtension(URL url)
url
- the URLpublic static File getFile(URL url)
url
- the URLpublic static boolean isDirectory(URL url)
url
- the URLpublic static List<URL> getChildren(URL url, boolean strict)
File.listFiles()
, in a List rather than an array.
strict
parameter is false, it will return the first level entries of the zip file. For example, for
this zip file:
myZipFile.zip ==> entry1 ==> entry2 ==> directory1/entry3 ==> directory1/entry4The method will return the following list:
myZipFile.zip!entry1
myZipFile.zip!entry2
myZipFile.zip!directory1
myZipFile.zip ==> entry1 ==> entry2 ==> directory1/entry3 ==> directory1/entry4The method will return the following list for the URL for the
myZipFile.zip!directory1/
entry:
myZipFile.zip!entry1
myZipFile.zip!entry2
url
- the URLstrict
- true if children in jar or zip files should not be taken into account, except if the parent URL is itself a child of a zip or jar filepublic static File getFile(String path)
path
- the pathpublic static File getFile(String path, boolean filterExisting)
filterExisting
is truepath
- the pathfilterExisting
- true if the method will return null if the file does not existpublic static File getFile(File dir, String path)
dir
- the directory which will be used as the parent of the file if the path is not absolute. If this directory is null, the user directory will be
usedpath
- the pathpublic static File getFile(File dir, String path, boolean filterExisting)
filterExisting
is truedir
- the directory which will be used as the parent of the file if the path is not absolute. If this directory is null, the user directory will be
usedpath
- the pathfilterExisting
- true if the method will return null if the file does not existpublic static String getEscapedName(String name)
name
- the namepublic static File createFile(File dir, String path)
dir
- the base directorypath
- the pathpublic static URL getProtectedURL(File file) throws MalformedURLException
file
- the fileMalformedURLException
- if the conversion to an URL of the File lead to a MalformedURLExceptionpublic static URL getURL(File baseDir, String path) throws MalformedURLException
baseDir
- the base directorypath
- the relative or absolute pathMalformedURLException
- if the conversion to an URL of the path lead to a MalformedURLExceptionpublic static String getAbsolutePath(File baseDir, String path) throws MalformedURLException
baseDir
- the base directorypath
- the relative or absolute pathMalformedURLException
- if the conversion to an URL of the path lead to a MalformedURLExceptionpublic static String getAbsolutePath(File baseDir, String path, boolean filterExistingURLs) throws MalformedURLException
filterExistingURLs
is true;
baseDir
- the base directorypath
- the relative or absolute pathfilterExistingURLs
- if true, return true for a not existing URLsMalformedURLException
- if the conversion to an URL of the path lead to a MalformedURLExceptionpublic static URL getURL(File baseDir, String path, boolean filterExistingURLs) throws MalformedURLException
filterExistingURLs
is true;
baseDir
- the base directorypath
- the relative or absolute pathfilterExistingURLs
- if true, return true for a not existing URLsMalformedURLException
- if the conversion to an URL of the path lead to a MalformedURLExceptionpublic static boolean isAbsolute(String path)
path
- the pathpublic static boolean isAbsoluteURI(String path)
path
- the URI pathpublic static String getAbsolutePath(URL baseURL, String relativePath)
baseURL
- the base URLrelativePath
- the relative pathpublic static URL getAbsoluteURL(URL baseURL, String relativePath)
baseURL
- the base URLrelativePath
- the relative pathpublic static URL makeAbsoluteURLPath(String path) throws MalformedURLException
path
- the pathMalformedURLException
public static File getAbsoluteFile(File baseDir, String relativePath)
baseDir
- the base directoryrelativePath
- the relative pathpublic static File getCompatibleFile(File file, String[] exts)
file
- the Fileexts
- the array of allowed extensionspublic static File getCompatibleFile(File file, String[] exts, String defaultExt)
file
- the Fileexts
- the array of allowed extensionsdefaultExt
- the default extensionpublic static File getCompatibleFile(File file, Set<String> extensions, String defaultExt)
file
- the Fileextensions
- the set of allowed extensionsdefaultExt
- the default extension (maybe null)public static File getCompatibleFile(File file, String ext)
file
- the Fileext
- the allowed extensionpublic static String getText(File file) throws IOException
file
- the FileIOException
public static String getText(URL url) throws IOException
url
- the URLIOException
public static File[] getFilesFromURLList(List<URL> list)
list
- the list of URLspublic static File[] getFilesFromURLList(List<URL> list, boolean filterExistingURLs)
list
- the list of URLsfilterExistingURLs
- true if only URL which exist on the network will be added to the resultpublic static List<URL> getURLListFromFiles(File[] files)
files
- the FIles arraypublic static List<URL> getURLListFromFiles(File[] files, boolean filterExistingFiles)
files
- the list of FilesfilterExistingFiles
- true if only Files which exist on the network will be added to the resultpublic static List<URL> getURLsFromString(File baseDir, String urlList) throws MalformedURLException
baseDir
- the base directoryurlList
- the list of URLs as a String separated with a ";"MalformedURLException
- if the conversion to an URL of one of the Strings lead to a MalformedURLExceptionpublic static List<URL> getURLsFromString(File baseDir, String urlList, boolean filterExistingURLs) throws MalformedURLException
baseDir
- the base directoryurlList
- the list of URLs as a String separated with a ";"filterExistingURLs
- if true, remove not existing URLs from the listMalformedURLException
- if the conversion to an URL of one of the Files lead to a MalformedURLExceptionpublic static List<URL> getURLsFromString(URL baseDir, String urlList) throws MalformedURLException
baseDir
- the base directoryurlList
- the list of URLs as a String separated with a ";"MalformedURLException
- if the conversion to an URL of one of the Files lead to a MalformedURLExceptionpublic static List<URL> getURLsFromString(URL baseDir, String urlList, boolean filterExistingURLs) throws MalformedURLException
baseDir
- the base directoryurlList
- the list of URLs as a String separated with a ";"filterExistingURLs
- if true, remove not existing URLs from the listMalformedURLException
public static URL[] getURLs(File dir, String paths)
dir
- the base directorypaths
- the list of URLs as a String separated by ";"public static URL[] getURLs(File dir, String paths, boolean filterExistingURLs)
dir
- the base directorypaths
- the list of URLs as a String separated by ";"filterExistingURLs
- if true, remove not existing URLs from the listpublic static boolean isAncestor(File ancestor, File file)
ancestor
- the ancestor filefile
- the filepublic static boolean isAncestor(URL ancestor, URL url)
ancestor
- the ancestor URLurl
- the URLpublic static boolean isRelativeTo(File baseDir, File file)
baseDir
- the directoryfile
- the filepublic static String getRelativePath(URL baseURL, URL url)
getRelativePath(java.net.URL, java.net.URL, boolean)
with the strict
parameter set to true.baseURL
- the base directoryurl
- the URLpublic static String getDrive(File file)
file
- the filepublic static String getRelativePath(URL baseURL, URL url, boolean strict)
baseURL
- the base directoryurl
- the URLstrict
- true if this will fall back to the absolute path of the URL if the File is not under the base directory. If this parameter is true, this
will have the same result as getRelativePath(java.io.File, java.io.File)
public static String getRelativePath(File baseDir, File file)
getRelativePath(java.io.File, java.io.File, boolean)
with the strict
parameter set to true.baseDir
- the base directoryfile
- the Filepublic static boolean isRoot(File dir)
dir
- the directorypublic static String getRelativePath(File baseDir, File file, boolean strict)
baseDir
- the base directoryfile
- the Filestrict
- true if this will fall back to the absolute path of the File if the File is not under the base directory. If this parameter is true, this
will have the same result as getRelativePath(java.io.File, java.io.File)
public static URL collapse(URL url) throws MalformedURLException
..
constructs.url
- the URLMalformedURLException
- if the collapsing of the URL leads to a malformed URL (this should normally never happen, except if the input URL
is itself Malformed)public static boolean sameURL(URL url1, URL url2)
url1
- the first URLurl2
- the second URLpublic static int getResponseCode(URL url, Proxy proxy) throws IOException
url
- the URLproxy
- the proxy (can be null, in that case no proxy will be used)IOException
- if an I/O exception occurspublic static int getResponseCode(URL url, Proxy proxy, int timeOut) throws IOException
url
- the URLproxy
- the proxy (can be null, in that case no proxy will be used)timeOut
- the timeOut (-1 for no timeOut)IOException
- if an I/O exception occurspublic static int getResponseCode(URL url, Proxy proxy, String userAgent) throws IOException
url
- the URLproxy
- the proxy (can be null, in that case no proxy will be used)userAgent
- the user agent. If the user agent is null, the FIREFOX10_USERAGENT
will be used by defaultIOException
- if an I/O exception occursgetResponseCode(java.net.URL, java.net.Proxy, java.lang.String, int)
public static int getResponseCode(URL url, Proxy proxy, String userAgent, int timeOut) throws IOException
HttpURLConnection
on the URLurl
- the URLproxy
- the proxy (can be null, in that case no proxy will be used)userAgent
- the user agent. If the user agent is null, the FIREFOX10_USERAGENT
will be used by defaulttimeOut
- the timeOut (-1 for no timeOut)IOException
- if an I/O exception occurspublic static int getResponseCode(URL url) throws IOException
url
- the URLIOException
- if an I/O exception occursgetResponseCode(java.net.URL, java.net.Proxy, int)
public static int getResponseCode(URL url, int timeOut) throws IOException
url
- the URLtimeOut
- the timeOut (-1 for no timeOut)IOException
- if an I/O exception occursgetResponseCode(java.net.URL, java.net.Proxy)
public static boolean isArchive(URL url)
url
- the urlpublic static boolean isArchive(File f)
f
- the Filepublic static boolean isURLFound(URL url)
isURLFound(java.net.URL, java.net.Proxy, java.lang.String, int, int)
with no proxy and a default FireFox 10 User Agent. For this method, 301 or
308 return codes will be accepted as valid responses (URL found).url
- the URLisURLFound(java.net.URL, java.net.Proxy, java.lang.String, int, int)
public static boolean isURLFound(URL url, int options)
isURLFound(java.net.URL, java.net.Proxy, java.lang.String, int, int)
with no proxy and a default FireFox 10 User Agent.
OPTION_ACCEPT301CODE
: if 301 or 308 return codes will be accepted as valid responses (URL found)OPTION_FOLLOWREDIRECT
: if redirection links will be followed and used to check that the links existsOPTION_FILEEXIST_SKIP_QUERIES
: by considering that URL with queries don't existOPTION_FILEEXIST_SKIP_PHP
: by considering that URL which point to php resources don't existboolean found = isURLFound(url, FileUtilities.OPTION_ACCEPT301CODE | FileUtilities.OPTION_FOLLOWREDIRECT);
url
- the URLoptions
- the optionspublic static boolean isURLFound(URL url, int options, int timeOut)
isURLFound(java.net.URL, java.net.Proxy, java.lang.String, int, int)
with no proxy and a default FireFox 10 User Agent.
OPTION_ACCEPT301CODE
: if 301 or 308 return codes will be accepted as valid responses (URL found)OPTION_FOLLOWREDIRECT
: if redirection links will be followed and used to check that the links existsOPTION_FILEEXIST_SKIP_QUERIES
: by considering that URL with queries don't existOPTION_FILEEXIST_SKIP_PHP
: by considering that URL which point to php resources don't existboolean found = isURLFound(url, FileUtilities.OPTION_ACCEPT301CODE | FileUtilities.OPTION_FOLLOWREDIRECT);
url
- the URLoptions
- the optionstimeOut
- the timeOut (-1 for no timeOut)public static boolean isURLFound(URL url, Proxy proxy)
isURLFound(java.net.URL, java.net.Proxy, java.lang.String, int, int)
with a default FireFox 10 User Agent. For this method, 301 or 308 return
codes will be accepted as valid responses (URL found).url
- the URLproxy
- the proxy for http URLs (can be null, in that case no proxy will be used)public static boolean isURLFound(URL url, Proxy proxy, int timeOut)
isURLFound(java.net.URL, java.net.Proxy, java.lang.String)
with a default FireFox 10 User Agent. For this method, 301 or 308 return codes will be
accepted as valid responses (URL found).url
- the URLproxy
- the proxy for http URLs (can be null, in that case no proxy will be used)timeOut
- the timeOut (-1 for no timeOut)public static boolean isURLFound(URL url, Proxy proxy, int options, int timeOut)
isURLFound(java.net.URL, java.net.Proxy, java.lang.String)
with a default FireFox 10 User Agent.
OPTION_ACCEPT301CODE
: if 301 or 308 return codes will be accepted as valid responses (URL found)OPTION_FOLLOWREDIRECT
: if redirection links will be followed and used to check that the links existsOPTION_FILEEXIST_SKIP_QUERIES
: by considering that URL with queries don't existOPTION_FILEEXIST_SKIP_PHP
: by considering that URL which point to php resources don't existboolean found = isURLFound(url, FileUtilities.OPTION_ACCEPT301CODE | FileUtilities.OPTION_FOLLOWREDIRECT);
url
- the URLproxy
- the proxy for http URLs (can be null, in that case no proxy will be used)options
- the optionstimeOut
- the timeOut (-1 for no timeOut)public static boolean isURLFound(URL url, Proxy proxy, String userAgent)
url
- the URLproxy
- the proxy for http URLs (can be null, in that case no proxy will be used)userAgent
- the user agent. If the user agent is null, the FIREFOX10_USERAGENT
will be used by defaultpublic static boolean isURLFound(URL url, Proxy proxy, String userAgent, int timeOut)
url
- the URLproxy
- the proxy for http URLs (can be null, in that case no proxy will be used)userAgent
- the user agent. If the user agent is null, the FIREFOX10_USERAGENT
will be used by defaulttimeOut
- the timeOut (-1 for no timeOut)public static boolean isURLFound(URL url, Proxy proxy, String userAgent, int options, int timeOut)
HttpURLConnection
on the URLaccept301Code
is set to false, this will lead to return falseHttpURLConnection
will be checked:
OPTION_ACCEPT301CODE
: if 301 or 308 return codes will be accepted as valid responses (URL found)OPTION_FOLLOWREDIRECT
: if redirection links will be followed and used to check that the links existsOPTION_FILEEXIST_SKIP_QUERIES
: by considering that URL with queries don't existOPTION_FILEEXIST_SKIP_PHP
: by considering that URL which point to php resources don't existboolean found = isURLFound(url, FileUtilities.OPTION_ACCEPT301CODE | FileUtilities.OPTION_FOLLOWREDIRECT);For example:
url
- the URLproxy
- the proxy for http URLs (can be null, in that case no proxy will be used)userAgent
- the user agent. If the user agent is null, the FIREFOX10_USERAGENT
will be used by defaultoptions
- the optionstimeOut
- the timeOut (-1 for no timeOut)public static URL getRedirectURL(URL url) throws IOException
url
- IOException