code: public static String buildURIAsString(String scheme, String userInfo,
              String host, int port, String path, String query, String fragment) throws URISyntaxException {
          URI helperURI;
          try {
              helperURI = new URI(scheme, userInfo, host, port, path, query, fragment);
          } catch (URISyntaxException e) {
              return NetworkInterfaceURI.buildURIToString(scheme, userInfo, host, port, path, query, fragment);
          }
          return helperURI.toString();
      }
docs: Helper method for building URI as String
  @param scheme
  @param userInfo
  @param host
  @param port
  @param path
  @param query
  @param fragment
  @return
  @throws URISyntaxException