code: public static int getPort(String uriString) {
          try {
              return (new URI(uriString)).getPort();
          }
          catch (URISyntaxException e) {
              try {
                  return (new NetworkInterfaceURI(uriString)).getPort();
              }
              catch (IllegalArgumentException ne) {
                  throw new IllegalArgumentException(ne.getMessage(), ne);
              }
          }
      }
docs: Helper method for retrieving port
  @param uriString
  @return