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 .