code: public static InetSocketAddress createInetSocketAddress(String address, int defaultPort) {
          String original = address.trim();
          String host = original;
          int port = defaultPort;
  
          if (host.startsWith("[")) {
              // it is an address in [host] or [host]port format
              String[] s = original.split("\\]");
              if (s.length > 1) {
                  if (s[1].startsWith(":")) {
                      s[1] = s[1].substring(1);
                  }
                  port = computePort(s[1], 0);
              }
              host = s[0].substring(1);
          }
  
  
          if (host.indexOf(":") == host.lastIndexOf(":") && (host.indexOf(":") > -1)) {
              //There is exactly 1 ':' in the string, hence this is an IP4 address which includes a port
              String[] s = original.split("\\:");
              host = s[0];
              if (s.length > 1) {
                  port = computePort(s[1], 0);
              }
          }
          return new InetSocketAddress(host, port);
      }
docs: <p>Creates an InetSocketAddress given a host and optional port in a single String
  <p/>
  <p>This allows either IP4 or IP6 addresses (including port) to be provided as Strings as per rfc2732</p>
  
  @param address     the address in one of the following formats (the braces '[]'and colon ':' are literal here):
  host<br>
  [host]<br>
  [host]:port<br>
  [host]port<br>
  ip4host:port<br>
  @param defaultPort The default port to be used ONLY IF the string does not specify a port
  @see java.net.InetSocketAddress