@Test public void testIp4SocketAddressToString() throws UnknownHostException { for (Entry<String, String> e : validIpV4Hosts.entrySet()) { assertEquals(e.getKey() + ":9999", toSocketAddressString(new InetSocketAddress(InetAddress.getByAddress(unhex(e.getValue())), 9999))); } }
public static String toSocketAddressString(InetSocketAddress addr) { String port = String.valueOf(addr.getPort()); final StringBuilder sb; if (addr.isUnresolved()) { String hostname = getHostname(addr); sb = newSocketAddressStringBuilder(hostname, port, !isValidIpV6Address(hostname)); } else { InetAddress address = addr.getAddress(); String hostString = toAddressString(address); sb = newSocketAddressStringBuilder(hostString, port, address instanceof Inet4Address); } return sb.append(':').append(port).toString(); }
NetUtil { public static String toSocketAddressString(InetSocketAddress addr) { String port = String.valueOf(addr.getPort()); final StringBuilder sb; if (addr.isUnresolved()) { String hostname = getHostname(addr); sb = newSocketAddressStringBuilder(hostname, port, !isValidIpV6Address(hostname)); } else { InetAddress address = addr.getAddress(); String hostString = toAddressString(address); sb = newSocketAddressStringBuilder(hostString, port, address instanceof Inet4Address); } return sb.append(':').append(port).toString(); } }
NetUtil { public static String toSocketAddressString(InetSocketAddress addr) { String port = String.valueOf(addr.getPort()); final StringBuilder sb; if (addr.isUnresolved()) { String hostname = getHostname(addr); sb = newSocketAddressStringBuilder(hostname, port, !isValidIpV6Address(hostname)); } else { InetAddress address = addr.getAddress(); String hostString = toAddressString(address); sb = newSocketAddressStringBuilder(hostString, port, address instanceof Inet4Address); } return sb.append(':').append(port).toString(); } private  NetUtil(); }
NetUtil { public static String toSocketAddressString(InetSocketAddress addr) { String port = String.valueOf(addr.getPort()); final StringBuilder sb; if (addr.isUnresolved()) { String hostname = getHostname(addr); sb = newSocketAddressStringBuilder(hostname, port, !isValidIpV6Address(hostname)); } else { InetAddress address = addr.getAddress(); String hostString = toAddressString(address); sb = newSocketAddressStringBuilder(hostString, port, address instanceof Inet4Address); } return sb.append(':').append(port).toString(); } private  NetUtil(); static boolean isIpV4StackPreferred(); static boolean isIpV6AddressesPreferred(); static byte[] createByteArrayFromIpAddressString(String ipAddressString); static String intToIpAddress(int i); static String bytesToIpAddress(byte[] bytes); static String bytesToIpAddress(byte[] bytes, int offset, int length); static boolean isValidIpV6Address(String ip); static boolean isValidIpV6Address(CharSequence ip); static boolean isValidIpV4Address(CharSequence ip); static boolean isValidIpV4Address(String ip); static Inet6Address getByName(CharSequence ip); static Inet6Address getByName(CharSequence ip, boolean ipv4Mapped); static String toSocketAddressString(InetSocketAddress addr); static String toSocketAddressString(String host, int port); static String toAddressString(InetAddress ip); static String toAddressString(InetAddress ip, boolean ipv4Mapped); static String getHostname(InetSocketAddress addr); }
NetUtil { public static String toSocketAddressString(InetSocketAddress addr) { String port = String.valueOf(addr.getPort()); final StringBuilder sb; if (addr.isUnresolved()) { String hostname = getHostname(addr); sb = newSocketAddressStringBuilder(hostname, port, !isValidIpV6Address(hostname)); } else { InetAddress address = addr.getAddress(); String hostString = toAddressString(address); sb = newSocketAddressStringBuilder(hostString, port, address instanceof Inet4Address); } return sb.append(':').append(port).toString(); } private  NetUtil(); static boolean isIpV4StackPreferred(); static boolean isIpV6AddressesPreferred(); static byte[] createByteArrayFromIpAddressString(String ipAddressString); static String intToIpAddress(int i); static String bytesToIpAddress(byte[] bytes); static String bytesToIpAddress(byte[] bytes, int offset, int length); static boolean isValidIpV6Address(String ip); static boolean isValidIpV6Address(CharSequence ip); static boolean isValidIpV4Address(CharSequence ip); static boolean isValidIpV4Address(String ip); static Inet6Address getByName(CharSequence ip); static Inet6Address getByName(CharSequence ip, boolean ipv4Mapped); static String toSocketAddressString(InetSocketAddress addr); static String toSocketAddressString(String host, int port); static String toAddressString(InetAddress ip); static String toAddressString(InetAddress ip, boolean ipv4Mapped); static String getHostname(InetSocketAddress addr); static final Inet4Address LOCALHOST4; static final Inet6Address LOCALHOST6; static final InetAddress LOCALHOST; static final NetworkInterface LOOPBACK_IF; static final int SOMAXCONN; }