code: public static String modifyURIPath(String uri, String newPath) {
          try {
              URI uriObj = new URI(uri);
              return uriToString(URLUtils.modifyURIPath(uriObj, newPath));
          }
          catch (URISyntaxException e) {
              try {
                  return (new NetworkInterfaceURI(uri)).modifyURIPath(newPath);
              }
              catch (IllegalArgumentException ne) {
                  throw new IllegalArgumentException(ne.getMessage(), ne);
              }
          }
      }
docs: Helper method for modiffying the URI path
  @param uri
  @param newPath
  @return