# Class UriUtil

java.lang.Object
org.apache.tomcat.util.buf.UriUtil

public final class UriUtil extends Object
Utility class for working with URIs and URLs.

## Method Summary

Modifier and Type
Method
Description
`static URL`
`buildJarSafeUrl(File file)`
Builds a JAR-safe URL for the given file, with special characters escaped.
`static URL`
`buildJarUrl(File jarFile)`
Builds a JAR URL for the given JAR file.
`static URL`
`buildJarUrl(File jarFile, String entryPath)`
Builds a JAR URL for the given JAR file and entry path.
`static URL`
`buildJarUrl(String fileUrlString)`
Builds a JAR URL for the given file URL string.
`static URL`
`buildJarUrl(String fileUrlString, String entryPath)`
Builds a JAR URL for the given file URL string and entry path.
`static String`
`getWarSeparator()`
Returns the separator used in WAR URLs.
`static boolean`
`hasScheme(CharSequence uri)`
Determine if a URI string has a `scheme` component.
`static boolean`
`isAbsoluteURI(String path)`
Does the provided path start with `file:/` or `<protocol>://`.
`static URI`
`resolve(URI base, String target)`
Replicates the behaviour of `URI.resolve(String)` and adds support for URIs of the form `jar:file:/...` .
`static URL`
`warToJar(URL warUrl)`
Convert a URL of the form `war:file:...` to `jar:file:...`.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### hasScheme

public static boolean hasScheme(CharSequence uri)
Determine if a URI string has a `scheme` component.

Parameters:
  `uri` - The URI to test
Returns:
  `true` if a scheme is present, otherwise {code @false}

### buildJarUrl

public static URL buildJarUrl(File jarFile) throws MalformedURLException
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

public static URL buildJarUrl(File jarFile, String entryPath) throws MalformedURLException
Builds a JAR URL for the given JAR file and entry path.

Parameters:
  `jarFile` - the JAR file
  `entryPath` - the entry path within the JAR
Returns:
  the JAR URL
Throws:
  `MalformedURLException` - if URL creation fails

### buildJarUrl

public static URL buildJarUrl(String fileUrlString) throws MalformedURLException
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

public static URL buildJarUrl(String fileUrlString, String entryPath) throws MalformedURLException
Builds a JAR URL for the given file URL string and entry path.

Parameters:
  `fileUrlString` - the file URL string
  `entryPath` - the entry path within the JAR
Returns:
  the JAR URL
Throws:
  `MalformedURLException` - if URL creation fails

### buildJarSafeUrl

public static URL buildJarSafeUrl(File file) throws MalformedURLException
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

public static URL warToJar(URL warUrl) throws MalformedURLException
Convert a URL of the form `war:file:...` to `jar:file:...`.

Parameters:
  `warUrl` - The WAR URL to convert
Returns:
  The equivalent JAR URL
Throws:
  `MalformedURLException` - If the conversion fails

### getWarSeparator

public static String getWarSeparator()
Returns the separator used in WAR URLs.

Returns:
  the WAR separator string

### isAbsoluteURI

public static boolean isAbsoluteURI(String path)
Does the provided path start with `file:/` or `<protocol>://`.

Parameters:
  `path` - The path to test
Returns:
  `true` if the supplied path starts with one of the recognised sequences.

### resolve

public static URI resolve(URI base, String target) throws MalformedURLException, URISyntaxException
Replicates the behaviour of `URI.resolve(String)` and adds support for URIs of the form `jar:file:/...` .

Parameters:
  `base` - The base URI to resolve against
  `target` - The path to resolve
Returns:
  The resulting URI as per `URI.resolve(String)`
Throws:
  `MalformedURLException` - If the base URI cannot be converted to a URL
  `URISyntaxException` - If the resulting URL cannot be converted to a URI