private static String [ ] getHostAndPortFromBracketedHost ( String hostPortString ) { int colonIndex = 0 ; int closeBracketIndex = 0 ; checkArgument ( hostPortString . charAt ( 0 ) == ' ' , "Bracketed host-port string must start with a bracket: %s" , hostPortString ) ; colonIndex = hostPortString . indexOf ( ' ' ) ; closeBracketIndex = hostPortString . lastIndexOf ( ' ' ) ; checkArgument ( colonIndex > - 1 && closeBracketIndex > colonIndex , "Invalid bracketed host/port: %s" , hostPortString ) ; String host = hostPortString . substring ( 1 , closeBracketIndex ) ; if ( closeBracketIndex + 1 == hostPortString . length ( ) ) { return new String [ ] { host , "" } ; } else { checkArgument ( hostPortString . charAt ( closeBracketIndex + 1 ) == ' ' , "Only a colon may follow a close bracket: %s" , hostPortString ) ; for ( int i = closeBracketIndex + 2 ; i < hostPortString . length ( ) ; ++ i ) { checkArgument ( Character . isDigit ( hostPortString . charAt ( i ) ) , "Port must be numeric: %s" , hostPortString ) ; } return new String [ ] { host , hostPortString . substring ( closeBracketIndex + 2 ) } ; } }
Parses a bracketed host - port string throwing IllegalArgumentException if parsing fails .