Class UriUtil
java.lang.Object
org.apache.tomcat.util.buf.UriUtil
Utility class for working with URIs and URLs.
-
Method Summary
Modifier and TypeMethodDescriptionstatic URLbuildJarSafeUrl(File file) Builds a JAR-safe URL for the given file, with special characters escaped.static URLbuildJarUrl(File jarFile) Builds a JAR URL for the given JAR file.static URLbuildJarUrl(File jarFile, String entryPath) Builds a JAR URL for the given JAR file and entry path.static URLbuildJarUrl(String fileUrlString) Builds a JAR URL for the given file URL string.static URLbuildJarUrl(String fileUrlString, String entryPath) Builds a JAR URL for the given file URL string and entry path.static StringReturns the separator used in WAR URLs.static booleanhasScheme(CharSequence uri) Determine if a URI string has aschemecomponent.static booleanisAbsoluteURI(String path) Does the provided path start withfile:/or<protocol>://.static URIReplicates the behaviour ofURI.resolve(String)and adds support for URIs of the formjar:file:/....static URLConvert a URL of the formwar:file:...tojar:file:....
-
Method Details
-
hasScheme
Determine if a URI string has aschemecomponent.- Parameters:
uri- The URI to test- Returns:
trueif a scheme is present, otherwise {code @false}
-
buildJarUrl
Builds a JAR URL for the given JAR file.- Parameters:
jarFile- the JAR file- Returns:
- the JAR URL
- Throws:
MalformedURLException- if URL creation fails
-
buildJarUrl
Builds 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:
MalformedURLException- if URL creation fails
-
buildJarUrl
Builds a JAR URL for the given file URL string.- Parameters:
fileUrlString- the file URL string- Returns:
- the JAR URL
- Throws:
MalformedURLException- if URL creation fails
-
buildJarUrl
Builds 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:
MalformedURLException- if URL creation fails
-
buildJarSafeUrl
Builds a JAR-safe URL for the given file, with special characters escaped.- Parameters:
file- the file- Returns:
- the JAR-safe URL
- Throws:
MalformedURLException- if URL creation fails
-
warToJar
Convert a URL of the formwar:file:...tojar:file:....- Parameters:
warUrl- The WAR URL to convert- Returns:
- The equivalent JAR URL
- Throws:
MalformedURLException- If the conversion fails
-
getWarSeparator
Returns the separator used in WAR URLs.- Returns:
- the WAR separator string
-
isAbsoluteURI
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
Replicates 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:
MalformedURLException- If the base URI cannot be converted to a URLURISyntaxException- If the resulting URL cannot be converted to a URI
-