code: public static String authorityFromHostAndPort(String host, int port) {
      try {
        return new URI(null, null, host, port, null, null, null).getAuthority();
      } catch (URISyntaxException ex) {
        throw new IllegalArgumentException("Invalid host or port: " + host + " " + port, ex);
      }
    }
docs: Combine a host and port into an authority string.