public final class URIUtil extends Object
URI
class, and provides additional
path manipulation methods that are not available on the URI class.Modifier and Type | Method and Description |
---|---|
static URI |
append(URI base,
String extension)
Returns a new URI with all the same components as the given base URI,
but with a path component created by appending the given extension to the
base URI's path.
|
static URI |
fromString(String uriString)
Returns a URI corresponding to the given unencoded string.
|
static boolean |
isFileURI(URI uri)
Returns whether the given URI refers to a local file system URI.
|
static String |
lastSegment(URI location)
Returns the last segment of the given URI.
|
static URI |
makeAbsolute(URI relative,
URI baseURI)
Returns an absolute URI that is created by appending the given relative URI to
the given base.
|
static URI |
makeRelative(URI original,
URI baseURI)
Returns a URI equivalent to the given original URI, but relative to the given base
URI if possible.
|
static URI |
removeFileExtension(URI uri)
Returns a new URI which is the same as this URI but with the file extension removed
from the path part.
|
static boolean |
sameURI(URI uri1,
URI uri2)
Returns true if the two URIs are equal.
|
static File |
toFile(URI uri)
Returns the URI as a local file, or
null if the given
URI does not represent a local file. |
static URI |
toJarURI(URI uri,
IPath entryPath)
Returns a Java ARchive (JAR) URI for an entry in a jar or zip file.
|
static String |
toUnencodedString(URI uri)
Returns a string representation of the given URI that doesn't have illegal
characters encoded.
|
static URI |
toURI(URL url)
Returns the URL as a URI.
|
static URL |
toURL(URI uri)
Returns a URI as a URL.
|
public static URI append(URI base, String extension)
The important difference between this method
and URI.resolve(String)
is in the treatment of the final segment.
The URI resolve method drops the last segment if there is no trailing slash as
specified in section 5.2 of RFC 2396. This leads to unpredictable behaviour
when working with file: URIs, because the existence of the trailing slash
depends on the existence of a local file on disk. This method operates
like a traditional path append and always preserves all segments of the base path.
base
- The base URI to append toextension
- The unencoded path extension to be addedpublic static URI fromString(String uriString) throws URISyntaxException
uriString
- An unencoded URI stringURISyntaxException
- If the string cannot be formed into a valid URIpublic static boolean isFileURI(URI uri)
uri
- The URI to checktrue
if the URI is a local file system location, and false
otherwisepublic static String lastSegment(URI location)
null
for
a hierarchical URI with an empty path, and for opaque URIs whose scheme-specific
part cannot be interpreted as a path.public static URI removeFileExtension(URI uri)
The file extension portion is defined as the string following the last period (".") character in the last segment. If there is no period in the last segment, the path has no file extension portion. If the last segment ends in a period, the file extension portion is the empty string.
public static boolean sameURI(URI uri1, URI uri2)
URI.equals(Object)
returns true, if the string representation
of the URIs is equal, or if they URIs are represent the same local file.uri1
- The first URI to compareuri2
- The second URI to comparetrue
if the URIs are the same, and false
otherwise.public static File toFile(URI uri)
null
if the given
URI does not represent a local file.uri
- The URI to return the file fornull
public static URI toJarURI(URI uri, IPath entryPath)
The entry path parameter can optionally be used to obtain the URI of an entry
in a zip or jar file. If an entry path of null
is provided, the resulting
URI will represent the jar file itself.
uri
- The URI of a zip or jar fileentryPath
- The path of a file inside the jar, or null
to
obtain the URI for the jar file itself.JarURLConnection
public static URI toURI(URL url) throws URISyntaxException
url
- The URL to convert into a URIURISyntaxException
public static URL toURL(URI uri) throws MalformedURLException
MalformedURLException
public static String toUnencodedString(URI uri)
fromString(String)
.uri
- The URI to convert to string formatpublic static URI makeAbsolute(URI relative, URI baseURI)
This method is guaranteed to be the inverse of makeRelative(URI, URI)
.
That is, if R = makeRelative(O, B), then makeAbsolute(R, B), will return the original
URI O.
relative
- the relative URIbaseURI
- the base URIpublic static URI makeRelative(URI original, URI baseURI)
This method is equivalent to URI.relativize(java.net.URI)
, except for its
handling of file URIs. For file URIs, this method handles file system path devices.
If the URIs are not on the same device, then the original URI is returned.
original
- the original URIbaseURI
- the base URI
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.