Modifier and Type | Method and Description |
---|---|
static URI |
fromURL(URL url)
|
static URI |
getCanonicalParent(URI uri)
|
static String |
getName(URI uri)
Returns the name of the file or directory denoted by the specified
URI . |
static URI |
getParent(URI uri)
Returns the URI representing the parent of the specified
URI , or
null if uri is null or does not name a parent directory. |
static String |
getShortName(URI uri)
Returns the short name of the file or directory denoted by the specified
URI . |
static boolean |
isLocal(URI uri)
Tests whether the specified
URI represents a location that is
either a local file with scheme "file:" , or a local JAR file with
scheme "jar:file:" . |
static boolean |
isLocalFile(URI uri)
Tests whether the specified
URI represents a file path. |
static boolean |
isLocalJarFile(URI uri)
Tests whether the specified
URI represents a location that is a
local JAR file with scheme "jar:file:" . |
static URI |
relativePath(URI from,
URI to)
Constructs a relative path between the specified
from and provided
to . |
static URI |
toURI(URI baseURI,
String path)
|
public static URI fromURL(URL url)
URI
from the specified URL
.
This method functions in the same way as new URI(url.toString())
.
Note, any URL instance that complies with RFC 2396 can be converted to a URI. However, some URLs that are not strictly in compliance can not be converted to a URI.
url
- The URL
to convert to a URI
.URI
.IllegalArgumentException
- if this URL is not formatted strictly
according to to RFC2396 and cannot be converted to a URI.NullPointerException
- If the specified URL
is null.public static URI relativePath(URI from, URI to)
from
and provided
to
.from
- The URI
from which to start.to
- The URI
to which to end up.URI
, or null
if either specified
URIs are opaque.NullPointerException
- If from
or to
is null.public static boolean isLocalFile(URI uri)
URI
represents a file path. A URI is
considered a file if its scheme is "file" (case-insensitive), and its host
value is empty or equal to "localhost"
.uri
- The URI
.true
if the specified URI
represents a file path;
otherwise false
.NullPointerException
- If uri
is null.public static boolean isLocalJarFile(URI uri)
URI
represents a location that is a
local JAR file with scheme "jar:file:"
.
The compound scheme definition is unwrapped in order to determine if the
root resource locator in the URI is local. This method then uses
isLocalFile(URI)
to check whether uri
is local.
uri
- The URI
to test.true
if the specified URI
represents a location
that is local; otherwise false
.NullPointerException
- If uri
is null.public static boolean isLocal(URI uri)
URI
represents a location that is
either a local file with scheme "file:"
, or a local JAR file with
scheme "jar:file:"
.
URIs with compound scheme definitions, such as "jar:file:"
are
first unwrapped in order to digest the root resource locator in the URI.
This method then uses isLocalFile(URI)
to check whether
uri
is local.
uri
- The URI
to test.true
if the specified URI
represents a location
that is either a local file with scheme "file:"
, or a
local JAR file with scheme "jar:file:"
; otherwise
false
.NullPointerException
- If uri
is null.public static String getName(URI uri)
URI
. This is just the last name in the name sequence of
uri
. If the name sequence of uri
is empty, then the empty
string is returned.uri
- The URI
.URI
, or the empty string if the name sequence of
uri
is empty.NullPointerException
- If uri
is null.public static String getShortName(URI uri)
URI
. This is just the last name in the name sequence of
uri
, with its dot-extension removed if present. If the name
sequence of uri
is empty, then the empty string is returned.uri
- The URI
.URI
, or the empty string if the name sequence of
uri
is empty.NullPointerException
- If uri
is null.public static URI getParent(URI uri)
URI
, or
null
if uri
is null or does not name a parent directory.uri
- The URI
.URI
, or
null
if uri
does not name a parent directory.StringPaths.getParent(String)
public static URI getCanonicalParent(URI uri)
URI
, or null
if uri
is null or does not name a
parent directory (".."
and "."
path names are dereferenced
in a canonical URI
)).uri
- The URI
.URI
, or
null
if uri
is null or does not name a parent
directory (".."
and "."
path names are dereferenced
in a canonical URI
, and redundant '/'
path
separators are removed).StringPaths.getParent(String)
public static URI toURI(URI baseURI, String path)
baseURI
- The base URI of the path in the resulting URI
.path
- The child path off of baseURI
in the resulting
URI
.URI
created from the specified baseURI
parent
directory, and path
child path.IllegalArgumentException
- If the specified baseURI
contains
a query string; 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.NullPointerException
- If baseURI
or path
is null.Copyright © 2020 LibJ. All rights reserved.