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

Method toAddrString

output/java_guava/1.4.19/InetAddresses.java:346–360  ·  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

344
345
346 public static String toAddrString(InetAddress ip) {
347 Preconditions.checkNotNull(ip);
348 if (ip instanceof Inet4Address) {
349 // For IPv4, Java's formatting is good enough.
350 return ip.getHostAddress();
351 }
352 Preconditions.checkArgument(ip instanceof Inet6Address);
353 byte[] bytes = ip.getAddress();
354 int[] hextets = new int[IPV6_PART_COUNT];
355 for (int i = 0; i < hextets.length; i++) {
356 hextets[i] = Ints.fromBytes((byte) 0, (byte) 0, bytes[2 * i], bytes[2 * i + 1]);
357 }
358 compressLongestRunOfZeroes(hextets);
359 return hextetsToIPv6String(hextets);
360 }
361
362 /**
363 * 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