public class UrlUtils extends Object
限定符和类型 | 字段和说明 |
---|---|
static String |
FILE_URL_PREFIX
URL prefix for loading from the file system: "file:"
|
static String |
JAR_URL_SEPARATOR
Separator between JAR URL and file path within the JAR
|
static String |
URL_PROTOCOL_CODE_SOURCE
URL protocol for an entry from an OC4J jar file: "code-source"
|
static String |
URL_PROTOCOL_FILE
URL protocol for a file in the file system: "file"
|
static String |
URL_PROTOCOL_JAR
URL protocol for an entry from a jar file: "jar"
|
static String |
URL_PROTOCOL_VFS
URL protocol for a JBoss VFS resource: "vfs"
|
static String |
URL_PROTOCOL_VFSZIP
URL protocol for an entry from a JBoss jar file: "vfszip"
|
static String |
URL_PROTOCOL_WSJAR
URL protocol for an entry from a WebSphere jar file: "wsjar"
|
static String |
URL_PROTOCOL_ZIP
URL protocol for an entry from a zip file: "zip"
|
构造器和说明 |
---|
UrlUtils() |
限定符和类型 | 方法和说明 |
---|---|
static URL |
extractJarFileURL(URL jarUrl)
Extract the URL for the actual jar file from the given URL
(which may point to a resource in a jar file or to a jar file itself).
|
static File |
getFile(URI resourceUri)
Resolve the given resource URI to a
java.io.File ,
i.e. to a file in the file system. |
static File |
getFile(URI resourceUri,
String description)
Resolve the given resource URI to a
java.io.File ,
i.e. to a file in the file system. |
static File |
getFile(URL resourceUrl)
Resolve the given resource URL to a
java.io.File ,
i.e. to a file in the file system. |
static File |
getFile(URL resourceUrl,
String description)
Resolve the given resource URL to a
java.io.File ,
i.e. to a file in the file system. |
static boolean |
isFileURL(URL url)
Determine whether the given URL points to a resource in the file system,
that is, has protocol "file" or "vfs".
|
static boolean |
isJarURL(URL url)
Determine whether the given URL points to a resource in a jar file,
that is, has protocol "jar", "zip", "wsjar" or "code-source".
|
static URI |
toURI(String location)
Create a URI instance for the given location String,
replacing spaces with "%20" quotes first.
|
static URI |
toURI(URL url)
Create a URI instance for the given URL,
replacing spaces with "%20" quotes first.
|
static void |
useCachesIfNecessary(URLConnection con)
Set the
"useCaches" flag on the
given connection, preferring false but leaving the
flag at true for JNLP based resources. |
public static final String FILE_URL_PREFIX
public static final String URL_PROTOCOL_FILE
public static final String URL_PROTOCOL_JAR
public static final String URL_PROTOCOL_ZIP
public static final String URL_PROTOCOL_VFSZIP
public static final String URL_PROTOCOL_VFS
public static final String URL_PROTOCOL_WSJAR
public static final String URL_PROTOCOL_CODE_SOURCE
public static boolean isFileURL(URL url)
url
- the URL to checkpublic static boolean isJarURL(URL url)
"zip" and "wsjar" are used by BEA WebLogic Server and IBM WebSphere, respectively, but can be treated like jar files. The same applies to "code-source" URLs on Oracle OC4J, provided that the path contains a jar separator.
url
- the URL to checkpublic static URL extractJarFileURL(URL jarUrl) throws MalformedURLException
jarUrl
- the original URLMalformedURLException
- if no valid jar file URL could be extractedpublic static URI toURI(URL url) throws URISyntaxException
Furthermore, this method works on JDK 1.4 as well,
in contrast to the URL.toURI()
method.
url
- the URL to convert into a URI instanceURISyntaxException
- if the URL wasn't a valid URIURL.toURI()
public static URI toURI(String location) throws URISyntaxException
location
- the location String to convert into a URI instanceURISyntaxException
- if the location wasn't a valid URIpublic static void useCachesIfNecessary(URLConnection con)
"useCaches"
flag on the
given connection, preferring false
but leaving the
flag at true
for JNLP based resources.con
- the URLConnection to set the flag onpublic static File getFile(URL resourceUrl) throws FileNotFoundException
java.io.File
,
i.e. to a file in the file system.resourceUrl
- the resource URL to resolveFileNotFoundException
- if the URL cannot be resolved to
a file in the file systempublic static File getFile(URL resourceUrl, String description) throws FileNotFoundException
java.io.File
,
i.e. to a file in the file system.resourceUrl
- the resource URL to resolvedescription
- a description of the original resource that
the URL was created for (for example, a class path location)FileNotFoundException
- if the URL cannot be resolved to
a file in the file systempublic static File getFile(URI resourceUri) throws FileNotFoundException
java.io.File
,
i.e. to a file in the file system.resourceUri
- the resource URI to resolveFileNotFoundException
- if the URL cannot be resolved to
a file in the file systempublic static File getFile(URI resourceUri, String description) throws FileNotFoundException
java.io.File
,
i.e. to a file in the file system.resourceUri
- the resource URI to resolvedescription
- a description of the original resource that
the URI was created for (for example, a class path location)FileNotFoundException
- if the URL cannot be resolved to
a file in the file systemCopyright © 2018 jretty-org. All rights reserved.