public static HostPort getHostAndPort(String input) {
    String host;
    int port;

    if (StringUtils.isEmpty(input)) {
      throw new IllegalArgumentException("Input string is null or empty");
    }

    // Check if the input contains a colon, which separates the host and port
    int colonIndex = input.lastIndexOf(':');
    if (colonIndex == -1) {
      throw new IllegalArgumentException("Input does not contain a port.");
    }

    // Extract the host and port parts
    host = input.substring(0, colonIndex);
    port = getPort(input.substring(colonIndex + 1));

    // Check if the host is not null or empty
    validateHostNotEmpty(host);

    // Handle IPv6 addresses enclosed in square brackets (e.g., [IPv6]:port)
    if (host.startsWith("[") && host.endsWith("]")) {
      host = host.substring(1, host.length() - 1); // Remove the square brackets
    }

    return new HostPort(host, port);
  }
Splits a given input string representing a Hostname or an IP address and port into an `HostPort` object.
The input string must be in the format of IPv4/IPv6/[IPv6]/hostname:port.

@param input The input string containing the Hostname/IP address and port, in the format 
             "IPv4:port", "[IPv6]:port", "IPv6:port", or "hostname:port".
@return A {@link HostPort} object containing the parsed IP address and port number.
@throws IllegalArgumentException If the input format is invalid, if the host is null or empty,
                                 or if the port number is invalid.
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/common/IPStackUtils.java