Parse a host and port string into a {@link HostAndPort}. The port is optional. Examples: {@code host:port} or
{@code host}

@param hostPortString
@return
195351
public static HostAndPort parse(String hostPortString) {

        LettuceAssert.notNull(hostPortString, "HostPortString must not be null");
        String host;
        String portString = null;

        if (hostPortString.startsWith("[")) {
            String[] hostAndPort = getHostAndPortFromBracketedHost(hostPortString);
            host = hostAndPort[0];
            portString = hostAndPort[1];
        } else {
            int colonPos = hostPortString.indexOf(':');
            if (colonPos >= 0 && hostPortString.indexOf(':', colonPos + 1) == -1) {
                // Exactly 1 colon. Split into host:port.
                host = hostPortString.substring(0, colonPos);
                portString = hostPortString.substring(colonPos + 1);
            } else {
                // 0 or 2+ colons. Bare hostname or IPv6 literal.
                host = hostPortString;
            }
        }

        int port = NO_PORT;
        if (!LettuceStrings.isEmpty(portString)) {
            // Try to parse the whole port string as a number.
            // JDK7 accepts leading plus signs. We don't want to.
            LettuceAssert.isTrue(!portString.startsWith("+"), String.format("Cannot port number: %s", hostPortString));
            try {
                port = Integer.parseInt(portString);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException(String.format("Cannot parse port number: %s", hostPortString));
            }
            LettuceAssert.isTrue(isValidPort(port), String.format("Port number out of range: %s", hostPortString));
        }

        return new HostAndPort(host, port);
    }
275214
public String getHostAndPort()
  {
    if (enablePlaintextPort) {
      if (plaintextPort < 0) {
        return HostAndPort.fromString(host).toString();
      } else {
        return HostAndPort.fromParts(host, plaintextPort).toString();
      }
    }
    return null;
  }
432803
public static List<InetSocketAddress> parse(String specs, int defaultPort) {
    List<InetSocketAddress> result = new ArrayList<InetSocketAddress>(1);
    if (specs == null) {
      result.add(new InetSocketAddress("localhost", defaultPort));
    }
    else {
      String[] specStrings = specs.split("[ ,]+");
      for (String specString : specStrings) {
        int colon = specString.indexOf(':');
        if (colon < 0 || colon == specString.length() - 1) {
          result.add(new InetSocketAddress(specString, defaultPort));
        } else {
          String hostname = specString.substring(0, colon);
          int port = Integer.parseInt(specString.substring(colon+1));
          result.add(new InetSocketAddress(hostname, port));
        }
      }
    }
    return result;
  }
1135296
public static UrlBuilder parse(URL url) {
        final UrlBuilder result = new UrlBuilder();

        if (url != null) {
            final String protocol = url.getProtocol();
            if (protocol != null && !protocol.isEmpty()) {
                result.withScheme(protocol);
            }

            final String host = url.getHost();
            if (host != null && !host.isEmpty()) {
                result.withHost(host);
            }

            final int port = url.getPort();
            if (port != -1) {
                result.withPort(port);
            }

            final String path = url.getPath();
            if (path != null && !path.isEmpty()) {
                result.withPath(path);
            }

            final String query = url.getQuery();
            if (query != null && !query.isEmpty()) {
                result.withQuery(query);
            }
        }

        return result;
    }
369209
public static String encodeHost(String host, String encoding) throws UnsupportedEncodingException {
		return HierarchicalUriComponents.encodeUriComponent(host, encoding, HierarchicalUriComponents.Type.HOST_IPV4);
	}
771620
public static NetworkPort remotePort(String hostname, int port){
        return new RemoteNetworkPort(hostname, port, NetworkPort.Type.TCP);
    }
487909
@Override
    public String parseString(String expressionString, PortletRequest request) {
        return getValue(expressionString, request, String.class);
    }
435218
public static List<String> splitToPairs(String hostPortQuorumList) {
    // split an address hot
    String[] strings = StringUtils.getStrings(hostPortQuorumList);
    int len = 0;
    if (strings != null) {
      len = strings.length;
    }
    List<String> tuples = new ArrayList<String>(len);
    if (strings != null) {
      for (String s : strings) {
        tuples.add(s.trim());
      }
    }
    return tuples;
  }
458813
function (host) {
        /*
        * For Host match, we are considering the port with the host, hence we are using getRemote() instead of getHost()
        * We need to address three cases for the host urlStr
        * 1. * It matches all the host + protocol,  hence we are not having any parsing logic for it.
        * 2. *.foo.bar.com Here the prefix could be anything but it should end with foo.bar.com
        * 3. foo.bar.com This is the absolute matching needs to done.
        */
        var matchRegexObject = this._matchPatternObject;
        return (
            this.matchAnyHost(matchRegexObject) ||
            this.matchAbsoluteHostPattern(matchRegexObject, host) ||
            this.matchSuffixHostPattern(matchRegexObject, host)
        );
    }
594115
public static ImmutableSortedSet<String> hosts(int...ports) {
        if (ports.length == 0) {
            return ImmutableSortedSet.of(
                    HostAndPort.fromParts("", Constants.DEFAULT_INTERNAL_PORT).toString());
        }
        ImmutableSortedSet.Builder<String> sbld = ImmutableSortedSet.naturalOrder();
        for (int p: ports) {
            sbld.add(HostAndPort.fromParts("", p).toString());
        }
        return sbld.build();
    }
858621
def _join_host_port(host, port):
    """"""
    template = "%s:%s"
    host_requires_bracketing = ':' in host or '%' in host
    if host_requires_bracketing:
        template = "[%s]:%s"
    return template % (host, port)
170350
public String connectAndBind(String host, int port,
            BindParameter bindParam) 
            throws IOException {
        return connectAndBind(host, port, bindParam, 60000);
    }
811136
def join_host_port(host, port):
    
    if ':' in host and not host.startswith('['):
        return '[%s]:%d' % (host, port)
    return '%s:%d' % (host, port)
292844
static String getHostString(InetSocketAddress socketAddress) {
    InetAddress address = socketAddress.getAddress();
    if (address == null) {
      // The InetSocketAddress was specified with a string (either a numeric IP or a host name). If
      // it is a name, all IPs for that name should be tried. If it is an IP address, only that IP
      // address should be tried.
      return socketAddress.getHostName();
    }
    // The InetSocketAddress has a specific address: we should only try that address. Therefore we
    // return the address and ignore any host name that may be available.
    return address.getHostAddress();
  }
734319
public static List<HostAndPort> splitToHostsAndPorts(String hostPortQuorumList) {
    // split an address hot
    String[] strings = StringUtils.getStrings(hostPortQuorumList);
    int len = 0;
    if (strings != null) {
      len = strings.length;
    }
    List<HostAndPort> list = new ArrayList<HostAndPort>(len);
    if (strings != null) {
      for (String s : strings) {
        list.add(HostAndPort.fromString(s.trim()).withDefaultPort(DEFAULT_PORT));
      }
    }
    return list;
  }
1190106
public UrlBuilder withPort(String port) {
        if (port == null || port.isEmpty()) {
            this.port = null;
        } else {
            with(port, UrlTokenizerState.PORT);
        }
        return this;
    }
203329
public static String normalizeHost(String host) {
        // if it is normalized IPv6 or could not be IPv6, return
        if (host.isEmpty() || host.charAt(0) == '[' || host.indexOf(':') < 0)
            return host;

        // normalize with [ ]
        return "[" + host + "]";
    }