Java URI to Relative URI resolvePath(URI root, String subPath)

Here you can find the source of resolvePath(URI root, String subPath)

Description

root: smb:/host/my path: path/blub ====> smb:/host/my/path/blub

License

Apache License

Parameter

Parameter Description
root The root path
subPath The sub path should not start with a slash

Return

Returns the resolved path

Declaration

public static URI resolvePath(URI root, String subPath) throws URISyntaxException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.URI;
import java.net.URISyntaxException;

public class Main {
    /**//w  w w  .j  a  va 2s.  c o m
     * root:   smb:/host/my
     * path:   path/blub
     * ====>   smb:/host/my/path/blub
     *
     * @param root The root path
     * @param subPath The sub path should not start with a slash
     * @return Returns the resolved path
     */
    public static URI resolvePath(URI root, String subPath) throws URISyntaxException {
        String rootStr = root.toString();

        if (subPath.startsWith("/")) {
            subPath = subPath.substring(1, subPath.length());
        }

        return new URI(rootStr + (!rootStr.endsWith("/") ? "/" : "") + subPath);
    }
}

Related

  1. resolveFile(final URI relativeURI)
  2. resolveFileName(URI uri)
  3. resolveFileNameNoExt(URI uri)
  4. resolveFileUri(String fullPageURI, File rootPath)
  5. resolvePartUri(URI sourcePartUri, URI targetUri)
  6. resolvePort(URI uri)
  7. resolveReferenceStartingWithQueryString(final URI baseURI, final URI reference)
  8. resolveRelativeURI(String baseURI, String uriRef)
  9. resolveRelativeURI(URI base, String rel)