android/guava/src/com/google/common/net/InetAddresses.java
public static String toAddrString(InetAddress ip) {
    checkNotNull(ip);
    if (ip instanceof Inet4Address) {
      // For IPv4, Java's formatting is good enough.
      return ip.getHostAddress();
    }
    checkArgument(ip instanceof Inet6Address);
    byte[] bytes = ip.getAddress();
    int[] hextets = new int[IPV6_PART_COUNT];
    for (int i = 0; i < hextets.length; i++) {
      hextets[i] = Ints.fromBytes((byte) 0, (byte) 0, bytes[2 * i], bytes[2 * i + 1]);
    }
    compressLongestRunOfZeroes(hextets);
    return hextetsToIPv6String(hextets);
  }
public static String toAddrString(InetAddress ip) {
    checkNotNull(ip);
    if (ip instanceof Inet4Address) {
      // For IPv4, Java's formatting is good enough.
      return ip.getHostAddress();
    }
    checkArgument(ip instanceof Inet6Address);
    byte[] bytes = ip.getAddress();
    int[] hextets = new int[IPV6_PART_COUNT];
    for (int i = 0; i < hextets.length; i++) {
      hextets[i] = Ints.fromBytes((byte) 0, (byte) 0, bytes[2 * i], bytes[2 * i + 1]);
    }
    compressLongestRunOfZeroes(hextets);
    return hextetsToIPv6String(hextets);
  }
public static String toAddrString ( InetAddress ip ) { checkNotNull ( ip ) ; if ( ip instanceof Inet4Address ) { // For IPv4, Java's formatting is good enough. return ip . getHostAddress ( ) ; } checkArgument ( ip instanceof Inet6Address ) ; byte [ ] bytes = ip . getAddress ( ) ; int [ ] hextets = new int [ IPV6_PART_COUNT ] ; for ( int i = 0 ; i < hextets . length ; i ++ ) { hextets [ i ] = Ints . fromBytes ( ( byte ) 0 , ( byte ) 0 , bytes [ 2 * i ] , bytes [ 2 * i + 1 ] ) ; } compressLongestRunOfZeroes ( hextets ) ; return hextetsToIPv6String ( hextets ) ; }
Returns the string representation of an {@link InetAddress}.

<p>For IPv4 addresses, this is identical to {@link InetAddress#getHostAddress()}, but for IPv6
addresses, the output follows <a href="http://tools.ietf.org/html/rfc5952">RFC 5952</a> section
4. The main difference is that this method uses "::" for zero compression, while Java's version
uses the uncompressed form.

<p>This method uses hexadecimal for all IPv6 addresses, including IPv4-mapped IPv6 addresses
such as "::c000:201". The output does not include a Scope ID.

@param ip {@link InetAddress} to be converted to an address string
@return {@code String} containing the text-formatted IP address
@since 10.0
Returns the string representation of an { @link InetAddress } .