@Test public void testFormatAddress() throws UnknownHostException { { String host = "1.2.3.4"; int port = 42; Assert.assertEquals(host + ":" + port, NetUtils.unresolvedHostAndPortToNormalizedString(host, port)); } { String host = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; int port = 42; Assert.assertEquals("[2001:db8:85a3::8a2e:370:7334]:" + port, NetUtils.unresolvedHostAndPortToNormalizedString(host, port)); } { String host = "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"; int port = 42; Assert.assertEquals("[2001:db8:85a3::8a2e:370:7334]:" + port, NetUtils.unresolvedHostAndPortToNormalizedString(host, port)); } { String host = "somerandomhostname"; int port = 99; Assert.assertEquals(host + ":" + port, NetUtils.unresolvedHostAndPortToNormalizedString(host, port)); } { String host = " somerandomhostname "; int port = 99; Assert.assertEquals(host.trim() + ":" + port, NetUtils.unresolvedHostAndPortToNormalizedString(host, port)); } { String host = "illegalhost."; int port = 42; try { NetUtils.unresolvedHostAndPortToNormalizedString(host, port); fail(); } catch (Exception ignored) {} host = "illegalhost:fasf"; try { NetUtils.unresolvedHostAndPortToNormalizedString(host, port); fail(); } catch (Exception ignored) {} } { String host = "1.2.3.4"; int port = -1; try { NetUtils.unresolvedHostAndPortToNormalizedString(host, port); fail(); } catch (Exception ignored) {} } { String host = "CamelCaseHostName"; int port = 99; Assert.assertEquals(host.toLowerCase() + ":" + port, NetUtils.unresolvedHostAndPortToNormalizedString(host, port)); } }
public static String unresolvedHostAndPortToNormalizedString(String host, int port) { Preconditions.checkArgument(port >= 0 && port < 65536, "Port is not within the valid range,"); return unresolvedHostToNormalizedString(host) + ":" + port; }
NetUtils { public static String unresolvedHostAndPortToNormalizedString(String host, int port) { Preconditions.checkArgument(port >= 0 && port < 65536, "Port is not within the valid range,"); return unresolvedHostToNormalizedString(host) + ":" + port; } }
NetUtils { public static String unresolvedHostAndPortToNormalizedString(String host, int port) { Preconditions.checkArgument(port >= 0 && port < 65536, "Port is not within the valid range,"); return unresolvedHostToNormalizedString(host) + ":" + port; }  }
NetUtils { public static String unresolvedHostAndPortToNormalizedString(String host, int port) { Preconditions.checkArgument(port >= 0 && port < 65536, "Port is not within the valid range,"); return unresolvedHostToNormalizedString(host) + ":" + port; }  static String getHostnameFromFQDN(String fqdn); static URL getCorrectHostnamePort(String hostPort); static int getAvailablePort(); static String unresolvedHostToNormalizedString(String host); static String unresolvedHostAndPortToNormalizedString(String host, int port); static String ipAddressToUrlString(InetAddress address); static String ipAddressAndPortToUrlString(InetAddress address, int port); static String socketAddressToUrlString(InetSocketAddress address); static String hostAndPortToUrlString(String host, int port); static Iterator<Integer> getPortRangeFromString(String rangeDefinition); static ServerSocket createSocketFromPorts(Iterator<Integer> portsIterator, SocketFactory factory); static String getWildcardIPAddress(); }
NetUtils { public static String unresolvedHostAndPortToNormalizedString(String host, int port) { Preconditions.checkArgument(port >= 0 && port < 65536, "Port is not within the valid range,"); return unresolvedHostToNormalizedString(host) + ":" + port; }  static String getHostnameFromFQDN(String fqdn); static URL getCorrectHostnamePort(String hostPort); static int getAvailablePort(); static String unresolvedHostToNormalizedString(String host); static String unresolvedHostAndPortToNormalizedString(String host, int port); static String ipAddressToUrlString(InetAddress address); static String ipAddressAndPortToUrlString(InetAddress address, int port); static String socketAddressToUrlString(InetSocketAddress address); static String hostAndPortToUrlString(String host, int port); static Iterator<Integer> getPortRangeFromString(String rangeDefinition); static ServerSocket createSocketFromPorts(Iterator<Integer> portsIterator, SocketFactory factory); static String getWildcardIPAddress();  }