public static URI appendPathToSingleUri(final URI uri, final String relativeUri, final String separator)
            throws URISyntaxException {

        if (uri == null) {
            return null;
        }

        if (relativeUri == null || relativeUri.isEmpty()) {
            return uri;
        }

        if (uri.getPath().length() == 0 && relativeUri.startsWith(separator)) {
            return new URI(uri.getScheme(), uri.getAuthority(), relativeUri, uri.getRawQuery(), uri.getRawFragment());
        }

        final StringBuilder pathString = new StringBuilder(uri.getPath());
        if (uri.getPath().endsWith(separator)) {
            pathString.append(relativeUri);
        }
        else {
            pathString.append(separator);
            pathString.append(relativeUri);
        }

        return new URI(uri.getScheme(), uri.getAuthority(), pathString.toString(), uri.getQuery(), uri.getFragment());
    }
public static URI appendPathToSingleUri(final URI uri, final String relativeUri, final String separator)
            throws URISyntaxException {

        if (uri == null) {
            return null;
        }

        if (relativeUri == null || relativeUri.isEmpty()) {
            return uri;
        }

        if (uri.getPath().length() == 0 && relativeUri.startsWith(separator)) {
            return new URI(uri.getScheme(), uri.getAuthority(), relativeUri, uri.getRawQuery(), uri.getRawFragment());
        }

        final StringBuilder pathString = new StringBuilder(uri.getPath());
        if (uri.getPath().endsWith(separator)) {
            pathString.append(relativeUri);
        }
        else {
            pathString.append(separator);
            pathString.append(relativeUri);
        }

        return new URI(uri.getScheme(), uri.getAuthority(), pathString.toString(), uri.getQuery(), uri.getFragment());
    }
public static URI appendPathToSingleUri ( final URI uri , final String relativeUri , final String separator ) throws URISyntaxException { if ( uri == null ) { return null ; } if ( relativeUri == null || relativeUri . isEmpty ( ) ) { return uri ; } if ( uri . getPath ( ) . length ( ) == 0 && relativeUri . startsWith ( separator ) ) { return new URI ( uri . getScheme ( ) , uri . getAuthority ( ) , relativeUri , uri . getRawQuery ( ) , uri . getRawFragment ( ) ) ; } final StringBuilder pathString = new StringBuilder ( uri . getPath ( ) ) ; if ( uri . getPath ( ) . endsWith ( separator ) ) { pathString . append ( relativeUri ) ; } else { pathString . append ( separator ) ; pathString . append ( relativeUri ) ; } return new URI ( uri . getScheme ( ) , uri . getAuthority ( ) , pathString . toString ( ) , uri . getQuery ( ) , uri . getFragment ( ) ) ; }
Appends a path to a URI correctly using the given separator.

@param uri
The base Uri.
@param relativeUri
The relative URI.
@param separator
the separator to use.
@return The appended Uri.
@throws URISyntaxException
a valid Uri cannot be constructed
Appends a path to a URI correctly using the given separator .