Java Utililty Methods URI to Path

List of utility methods to do URI to Path

Description

The list of methods to do URI to Path are organized into topic(s).

Method

StringgetPath(final URI uri)
get Path
return isFileUri(uri) ? uri.getPath() : uri.toASCIIString();
StringgetPath(final URI uri)
Resolves the specified URI, and returns an absolute file system path to the resource represented by the URI.
return getFile(uri).getAbsolutePath();
StringgetPath(String uriStr)
get Path
URI uri = null;
try {
    uri = new URI(uriStr);
} catch (URISyntaxException e) {
    throw new RuntimeException(e.getLocalizedMessage());
return uri == null ? null : uri.getPath();
StringgetPath(URI addr)
get Path
return getPathInternal(addr.getPath());
StringgetPath(URI uri)
get Path
String path = uri.getPath();
if (path == null) {
    path = uri.getSchemeSpecificPart();
return path;
URIgetPathAndQueryURI(URI requestUri)
get Path And Query URI
if (requestUri == null) {
    throw new NullPointerException("requestUri");
try {
    return new URI(null, null, requestUri.getPath(), requestUri.getQuery(), null);
} catch (URISyntaxException e) {
    IllegalArgumentException ex = new IllegalArgumentException(requestUri.toString());
    ex.initCause(e);
...
String[]getPathAsArray(URI uri)
get Path As Array
StringBuilder path = new StringBuilder(uri.getPath());
if (uri.getPath().equals("/") || uri.getPath().equals("\\")) {
    String back = "\"" + "\\" + "\"";
    String forward = "\"" + "/" + "\"";
    String ie = "(ie: " + back + " or " + forward + ")";
    throw new RuntimeException("URI path cannot be a root " + ie);
path.deleteCharAt(0);
...
StringgetPathByTrimmingEndingFileSeparator(URI uri)
Trim eventual ending File#separator .
Ex:
 "file:/a/b/c" -> "/a/b/c" "file:/a/b/c/" -> "/a/b/c" "file:/a/b/c.txt" -> "/a/b/c.txt" 
String path = uri.getPath();
if (path.endsWith(File.separator))
    return path.substring(0, path.length() - 1);
else
    return path;
String[]getPathComponents(URI uri)
get Path Components
if (uri == null || uri.getPath() == null) {
    return new String[0];
return uri.getPath().split("/");
StringgetPathParamValue(URI uri)
get Path Param Value
return getODataParamValueAsString(uri, FORWARDING_URI_PARAM_NAME_PATH);