MCPcopy Create free account
hub / github.com/antlr/codebuff / toAddrString

Method toAddrString

output/java_guava/1.4.16/InetAddresses.java:345–359  ·  view source on GitHub ↗

Returns the string representation of an InetAddress. For IPv4 addresses, this is identical to InetAddress#getHostAddress(), but for IPv6 addresses, the output follows RFC 5952 section 4. The main difference is that this method uses

(InetAddress ip)

Source from the content-addressed store, hash-verified

343
344
345 public static String toAddrString(InetAddress ip) {
346 Preconditions.checkNotNull(ip);
347 if (ip instanceof Inet4Address) {
348 // For IPv4, Java's formatting is good enough.
349 return ip.getHostAddress();
350 }
351 Preconditions.checkArgument(ip instanceof Inet6Address);
352 byte[] bytes = ip.getAddress();
353 int[] hextets = new int[IPV6_PART_COUNT];
354 for (int i = 0; i < hextets.length; i++) {
355 hextets[i] = Ints.fromBytes((byte) 0, (byte) 0, bytes[2 * i], bytes[2 * i + 1]);
356 }
357 compressLongestRunOfZeroes(hextets);
358 return hextetsToIPv6String(hextets);
359 }
360
361 /**
362 * Identify and mark the longest run of zeroes in an IPv6 address.

Callers 6

toUriStringMethod · 0.95
getCompatIPv4AddressMethod · 0.95
get6to4IPv4AddressMethod · 0.95
getTeredoInfoMethod · 0.95
getIsatapIPv4AddressMethod · 0.95

Calls 5

checkNotNullMethod · 0.95
checkArgumentMethod · 0.95
fromBytesMethod · 0.95
hextetsToIPv6StringMethod · 0.95

Tested by

no test coverage detected