public static String ipAddressToUrlString ( InetAddress address ) { if ( address == null ) { throw new NullPointerException ( "address is null" ) ; } else if ( address instanceof Inet4Address ) { return address . getHostAddress ( ) ; } else if ( address instanceof Inet6Address ) { return getIPv6UrlRepresentation ( ( Inet6Address ) address ) ; } else { throw new IllegalArgumentException ( "Unrecognized type of InetAddress: " + address ) ; } }
Encodes an IP address properly as a URL string . This method makes sure that IPv6 addresses have the proper formatting to be included in URLs .