Package org.apache.tomcat.util.buf
Class UriUtil
- java.lang.Object
-
- org.apache.tomcat.util.buf.UriUtil
-
public final class UriUtil extends java.lang.ObjectUtility class for working with URIs and URLs.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.net.URLbuildJarSafeUrl(java.io.File file)Builds a JAR-safe URL for the given file, with special characters escaped.static java.net.URLbuildJarUrl(java.io.File jarFile)Builds a JAR URL for the given JAR file.static java.net.URLbuildJarUrl(java.io.File jarFile, java.lang.String entryPath)Builds a JAR URL for the given JAR file and entry path.static java.net.URLbuildJarUrl(java.lang.String fileUrlString)Builds a JAR URL for the given file URL string.static java.net.URLbuildJarUrl(java.lang.String fileUrlString, java.lang.String entryPath)Builds a JAR URL for the given file URL string and entry path.static java.lang.StringgetWarSeparator()Returns the separator used in WAR URLs.static booleanhasScheme(java.lang.CharSequence uri)Determine if a URI string has aschemecomponent.static booleanisAbsoluteURI(java.lang.String path)Does the provided path start withfile:/or<protocol>://.static java.net.URIresolve(java.net.URI base, java.lang.String target)Replicates the behaviour ofURI.resolve(String)and adds support for URIs of the formjar:file:/....static java.net.URLwarToJar(java.net.URL warUrl)Convert a URL of the formwar:file:...tojar:file:....
-
-
-
Method Detail
-
hasScheme
public static boolean hasScheme(java.lang.CharSequence uri)
Determine if a URI string has aschemecomponent.- Parameters:
uri- The URI to test- Returns:
trueif a scheme is present, otherwise {code @false}
-
buildJarUrl
public static java.net.URL buildJarUrl(java.io.File jarFile) throws java.net.MalformedURLExceptionBuilds a JAR URL for the given JAR file.- Parameters:
jarFile- the JAR file- Returns:
- the JAR URL
- Throws:
java.net.MalformedURLException- if URL creation fails
-
buildJarUrl
public static java.net.URL buildJarUrl(java.io.File jarFile, java.lang.String entryPath) throws java.net.MalformedURLExceptionBuilds a JAR URL for the given JAR file and entry path.- Parameters:
jarFile- the JAR fileentryPath- the entry path within the JAR- Returns:
- the JAR URL
- Throws:
java.net.MalformedURLException- if URL creation fails
-
buildJarUrl
public static java.net.URL buildJarUrl(java.lang.String fileUrlString) throws java.net.MalformedURLExceptionBuilds a JAR URL for the given file URL string.- Parameters:
fileUrlString- the file URL string- Returns:
- the JAR URL
- Throws:
java.net.MalformedURLException- if URL creation fails
-
buildJarUrl
public static java.net.URL buildJarUrl(java.lang.String fileUrlString, java.lang.String entryPath) throws java.net.MalformedURLExceptionBuilds a JAR URL for the given file URL string and entry path.- Parameters:
fileUrlString- the file URL stringentryPath- the entry path within the JAR- Returns:
- the JAR URL
- Throws:
java.net.MalformedURLException- if URL creation fails
-
buildJarSafeUrl
public static java.net.URL buildJarSafeUrl(java.io.File file) throws java.net.MalformedURLExceptionBuilds a JAR-safe URL for the given file, with special characters escaped.- Parameters:
file- the file- Returns:
- the JAR-safe URL
- Throws:
java.net.MalformedURLException- if URL creation fails
-
warToJar
public static java.net.URL warToJar(java.net.URL warUrl) throws java.net.MalformedURLExceptionConvert a URL of the formwar:file:...tojar:file:....- Parameters:
warUrl- The WAR URL to convert- Returns:
- The equivalent JAR URL
- Throws:
java.net.MalformedURLException- If the conversion fails
-
getWarSeparator
public static java.lang.String getWarSeparator()
Returns the separator used in WAR URLs.- Returns:
- the WAR separator string
-
isAbsoluteURI
public static boolean isAbsoluteURI(java.lang.String path)
Does the provided path start withfile:/or<protocol>://.- Parameters:
path- The path to test- Returns:
trueif the supplied path starts with one of the recognised sequences.
-
resolve
public static java.net.URI resolve(java.net.URI base, java.lang.String target) throws java.net.MalformedURLException, java.net.URISyntaxExceptionReplicates the behaviour ofURI.resolve(String)and adds support for URIs of the formjar:file:/....- Parameters:
base- The base URI to resolve againsttarget- The path to resolve- Returns:
- The resulting URI as per
URI.resolve(String) - Throws:
java.net.MalformedURLException- If the base URI cannot be converted to a URLjava.net.URISyntaxException- If the resulting URL cannot be converted to a URI
-
-