public static URI addPathComponent ( URI uri , String component ) { if ( uri != null && component != null ) try { return new URI ( uri . getScheme ( ) , uri . getUserInfo ( ) , uri . getHost ( ) , uri . getPort ( ) , Optional . ofNullable ( uri . getPath ( ) ) . map ( path -> join ( path , component , ' ' ) ) . orElse ( component ) , uri . getQuery ( ) , uri . getFragment ( ) ) ; } catch ( URISyntaxException use ) { throw new IllegalArgumentException ( "Could not add path component \"" + component + "\" to " + uri + ": " + use . getMessage ( ) , use ) ; } return uri ; }
This method adds a component to the path of an URI .