Class URIUtil
URI
class, and provides
additional path manipulation methods that are not available on the URI class.- Since:
- org.eclipse.equinox.common 3.5
- Restriction:
- This class is not intended to be instantiated by clients.
-
Method Summary
Modifier and TypeMethodDescriptionstatic URI
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
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
Returns true if the two URIs are equal.static File
Returns the URI as a local file, ornull
if the given URI does not represent a local file.static URI
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
An UNC-safe factory the the URI-ctorstatic URI
toURI
(String scheme, String userInfo, String host, int port, String path, String query, String fragment) An UNC-safe factory the the URI-ctorstatic URI
An UNC-safe factory the the URI-ctorstatic URI
An UNC-safe factory the the URI-ctorstatic URI
Returns the URL as a URI.static URL
Returns a URI as a URL.
-
Method Details
-
append
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.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.- Parameters:
base
- The base URI to append toextension
- The unencoded path extension to be added- Returns:
- The appended URI
-
fromString
Returns a URI corresponding to the given unencoded string. This method will take care of encoding any characters that must be encoded according to the URI specification. This method must not be called with a string that already contains an encoded URI, since this will result in the URI escape character ('%') being escaped itself.- Parameters:
uriString
- An unencoded URI string- Returns:
- A URI corresponding to the given string
- Throws:
URISyntaxException
- If the string cannot be formed into a valid URI
-
isFileURI
Returns whether the given URI refers to a local file system URI.- Parameters:
uri
- The URI to check- Returns:
true
if the URI is a local file system location, andfalse
otherwise
-
lastSegment
Returns the last segment of the given URI. For a hierarchical URL this returns the last segment of the path. For opaque URIs this treats the scheme-specific part as a path and returns the last segment. Returnsnull
for a hierarchical URI with an empty path, and for opaque URIs whose scheme-specific part cannot be interpreted as a path. -
removeFileExtension
Returns a new URI which is the same as this URI but with the file extension removed from the path part. If this URI does not have an extension, this path is returned.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.
- Returns:
- the new URI
-
sameURI
Returns true if the two URIs are equal. URIs are considered equal ifURI.equals(Object)
returns true, if the string representation of the URIs is equal, or if they URIs are represent the same local file.- Parameters:
uri1
- The first URI to compareuri2
- The second URI to compare- Returns:
true
if the URIs are the same, andfalse
otherwise.
-
toFile
Returns the URI as a local file, ornull
if the given URI does not represent a local file.- Parameters:
uri
- The URI to return the file for- Returns:
- The local file corresponding to the given URI, or
null
-
toJarURI
Returns a Java ARchive (JAR) URI for an entry in a jar or zip file. The given input URI should represent a zip or jar file, but this method will not check for existence or validity of a file at the given URI.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.- Parameters:
uri
- The URI of a zip or jar fileentryPath
- The path of a file inside the jar, ornull
to obtain the URI for the jar file itself.- Returns:
- A URI with the "jar" scheme for the given input URI and entry path
- See Also:
-
toURI
Returns the URL as a URI. This method will handle URLs that are not properly encoded (for example they contain unencoded space characters).- Parameters:
url
- The URL to convert into a URI- Returns:
- A URI representing the given URL
- Throws:
URISyntaxException
-
toURI
An UNC-safe factory the the URI-ctor- Parameters:
scheme
- Scheme namessp
- Scheme-specific partfragment
- Fragment- Returns:
- The new URI from the given components
- Throws:
URISyntaxException
- If the URI string constructed from the given components violates RFC 2396- Since:
- 3.17
- See Also:
-
toURI
public static URI toURI(String scheme, String userInfo, String host, int port, String path, String query, String fragment) throws URISyntaxException An UNC-safe factory the the URI-ctor- Parameters:
scheme
- Scheme nameuserInfo
- User name and authorization informationhost
- Host nameport
- Port numberpath
- Pathquery
- Queryfragment
- Fragment- Returns:
- The new hierarchical URI from the given components.
- Throws:
URISyntaxException
- If both a scheme and a path are given but the path is relative, if the URI string constructed from the given components violates RFC 2396, or if the authority component of the string is present but cannot be parsed as a server-based authority- Since:
- 3.17
- See Also:
-
toURI
public static URI toURI(String scheme, String host, String path, String fragment) throws URISyntaxException An UNC-safe factory the the URI-ctor- Parameters:
scheme
- Scheme namehost
- Host namepath
- Pathfragment
- Fragment- Returns:
- The new hierarchical URI from the given components
- Throws:
URISyntaxException
- If the URI string constructed from the given components violates RFC 2396- Since:
- 3.17
- See Also:
-
toURI
public static URI toURI(String scheme, String authority, String path, String query, String fragment) throws URISyntaxException An UNC-safe factory the the URI-ctor- Parameters:
scheme
- Scheme nameauthority
- Authoritypath
- Pathquery
- Queryfragment
- Fragment- Returns:
- The new hierarchical URI from the given components
- Throws:
URISyntaxException
- If both a scheme and a path are given but the path is relative, if the URI string constructed from the given components violates RFC 2396, or if the authority component of the string is present but cannot be parsed as a server-based authority- Since:
- 3.17
- See Also:
-
toURL
Returns a URI as a URL.Better use
URI.toURL()
instead.- Throws:
MalformedURLException
-
toUnencodedString
Returns a string representation of the given URI that doesn't have illegal characters encoded. This string is suitable for later passing tofromString(String)
.- Parameters:
uri
- The URI to convert to string format- Returns:
- An unencoded string representation of the URI
-
makeAbsolute
Returns an absolute URI that is created by appending the given relative URI to the given base. If therelative
URI is already absolute it is simply returned.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.- Parameters:
relative
- the relative URIbaseURI
- the base URI- Returns:
- an absolute URI
-
makeRelative
Returns a URI equivalent to the given original URI, but relative to the given base URI if possible.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.- Parameters:
original
- the original URIbaseURI
- the base URI- Returns:
- a relative URI
-