InetSocketAddress parseHostPortPair(String str) throws IOException {
  str=str.trim();
  if (str.isEmpty()) {
    throw new IOException("No hostname:port pair given.");
  }
  int bracketBegin=str.indexOf('[');
  if (bracketBegin == 0) {
    int bracketEnd=str.indexOf(']');
    if (bracketEnd < 0) {
      throw new IOException("Found left bracket, but no corresponding " + "right bracket, in " + str);
    }
    String host=str.substring(bracketBegin + 1,bracketEnd);
    int port=parseColonPort(str.substring(bracketEnd + 1));
    return InetSocketAddress.createUnresolved(host,port);
  }
 else   if (bracketBegin > 0) {
    throw new IOException("Found a left bracket that wasn't at the " + "start of the host:port pair in " + str);
  }
 else {
    int colon=str.indexOf(':');
    if (colon <= 0) {
      throw new IOException("No port component found in " + str);
    }
    String host=str.substring(0,colon);
    int port=parseColonPort(str.substring(colon));
    return InetSocketAddress.createUnresolved(host,port);
  }
}

InetSocketAddress parseHostPortPair ( String str ) throws IOException { str = str . trim ( ) ; if ( str . isEmpty ( ) ) { throw new IOException ( "No hostname:port pair given." ) ; } int bracketBegin = str . indexOf ( '[' ) ; if ( bracketBegin == 0 ) { int bracketEnd = str . indexOf ( ']' ) ; if ( bracketEnd < 0 ) { throw new IOException ( "Found left bracket, but no corresponding " + "right bracket, in " + str ) ; } String host = str . substring ( bracketBegin + 1 , bracketEnd ) ; int port = parseColonPort ( str . substring ( bracketEnd + 1 ) ) ; return InetSocketAddress . createUnresolved ( host , port ) ; } else if ( bracketBegin > 0 ) { throw new IOException ( "Found a left bracket that wasn't at the " + "start of the host:port pair in " + str ) ; } else { int colon = str . indexOf ( ':' ) ; if ( colon <= 0 ) { throw new IOException ( "No port component found in " + str ) ; } String host = str . substring ( 0 , colon ) ; int port = parseColonPort ( str . substring ( colon ) ) ; return InetSocketAddress . createUnresolved ( host , port ) ; } }
parse a hostname : port or ip : port pair .
