Java Utililty Methods URI to Relative URI

List of utility methods to do URI to Relative URI

Description

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

Method

URIrelativize(URI baseURI, URI uriToRelativize)
relativize
URI relativizedURI;
if (baseURI == null) {
    relativizedURI = uriToRelativize;
} else {
    try {
        File file = new File(baseURI);
        if (!file.isDirectory()) {
            File parent = file.getParentFile();
...
URIrelativizeFromBase(String uri, URI base)
relativize From Base
return relativizeFromBase(URI.create(uri), base);
URIresolve(String baseURI, String connectorURI)
resolve
return new URI(baseURI).resolve(new URI(connectorURI).getSchemeSpecificPart());
URIresolve(String path, URI... relativeTo)
resolve
if (path == null)
    return null;
final URI uri = new URI(path);
if (uri.isAbsolute())
    return uri;
else {
    for (URI parent : relativeTo) {
        if (parent != null) {
...
URIresolve(URI base, URI child)
resolve
URI ruri = base.resolve(child);
if ("file".equals(ruri.getScheme()) && !child.equals(ruri)) {
    if (base.getPath().startsWith("//") && !ruri.getPath().startsWith("//")) {
        String path = "///".concat(ruri.getPath());
        try {
            ruri = new URI("file", null, path, ruri.getQuery(), ruri.getFragment());
        } catch (URISyntaxException uris) {
return ruri;
URIresolve(URI baseURI, String reference)
Resolves a URI reference against a base URI.
if (reference.isEmpty()) {
    return new URI(baseURI.getScheme(), baseURI.getSchemeSpecificPart(), null);
if (WINDOWS_FILE_PATTERN.matcher(reference).lookingAt()) {
    return new File(reference).toURI();
reference = reference.replace('\\', '/');
URI refURI;
...
URIresolveAbsoluteURI(final URI relativeURI)
resolve Absolute URI
return getHtdocsDirectory().toURI().resolve(relativeURI);
FileresolveFile(final URI relativeURI)
resolve File
final File file = new File(resolveAbsoluteURI(relativeURI));
return file.isDirectory() ? new File(file, "index.html") : file;
StringresolveFileName(URI uri)
resolve File Name
String url = uri.toString();
return url.substring(url.lastIndexOf('/') + 1, url.length());
StringresolveFileNameNoExt(URI uri)
resolve File Name No Ext
String fileName = resolveFileName(uri);
return fileName.substring(0, fileName.lastIndexOf('.'));