@Test public void testCreateZeusIpString() { assertEquals("192.168.3.51:80", IpHelper.createZeusIpString("192.168.3.51", 80)); assertEquals("[ffff::ffff]:80", IpHelper.createZeusIpString("ffff::ffff", 80)); assertEquals("www.google.com:80", IpHelper.createZeusIpString("www.google.com", 80)); }
public static String createZeusIpString(String ipAddress, Integer port) { String errMsg; String fmt = "(address=\"%s\", port=%s)"; String ipOut = (ipAddress == null) ? "null" : ipAddress; String portOut = (port == null) ? "null" : port.toString(); String ipMsg = String.format(fmt, ipOut, portOut); if (ipAddress == null || port == null) { errMsg = String.format("ipAddress or port cann not be null. %s", ipMsg); throw new RuntimeException(errMsg); } if (IPUtils.isValidIpv4String(ipAddress)) { return String.format("%s:%d", ipAddress, port); } if (IPUtils.isValidIpv6String(ipAddress)) { return String.format("[%s]:%d", ipAddress, port); } if (ipAddress.matches(".*[a-zA-Z]+.*")) { return String.format("%s:%d", ipAddress, port); } errMsg = String.format("Cannot create string for ip address and port. %s", ipMsg); throw new RuntimeException(errMsg); }
IpHelper { public static String createZeusIpString(String ipAddress, Integer port) { String errMsg; String fmt = "(address=\"%s\", port=%s)"; String ipOut = (ipAddress == null) ? "null" : ipAddress; String portOut = (port == null) ? "null" : port.toString(); String ipMsg = String.format(fmt, ipOut, portOut); if (ipAddress == null || port == null) { errMsg = String.format("ipAddress or port cann not be null. %s", ipMsg); throw new RuntimeException(errMsg); } if (IPUtils.isValidIpv4String(ipAddress)) { return String.format("%s:%d", ipAddress, port); } if (IPUtils.isValidIpv6String(ipAddress)) { return String.format("[%s]:%d", ipAddress, port); } if (ipAddress.matches(".*[a-zA-Z]+.*")) { return String.format("%s:%d", ipAddress, port); } errMsg = String.format("Cannot create string for ip address and port. %s", ipMsg); throw new RuntimeException(errMsg); } }
IpHelper { public static String createZeusIpString(String ipAddress, Integer port) { String errMsg; String fmt = "(address=\"%s\", port=%s)"; String ipOut = (ipAddress == null) ? "null" : ipAddress; String portOut = (port == null) ? "null" : port.toString(); String ipMsg = String.format(fmt, ipOut, portOut); if (ipAddress == null || port == null) { errMsg = String.format("ipAddress or port cann not be null. %s", ipMsg); throw new RuntimeException(errMsg); } if (IPUtils.isValidIpv4String(ipAddress)) { return String.format("%s:%d", ipAddress, port); } if (IPUtils.isValidIpv6String(ipAddress)) { return String.format("[%s]:%d", ipAddress, port); } if (ipAddress.matches(".*[a-zA-Z]+.*")) { return String.format("%s:%d", ipAddress, port); } errMsg = String.format("Cannot create string for ip address and port. %s", ipMsg); throw new RuntimeException(errMsg); }  }
IpHelper { public static String createZeusIpString(String ipAddress, Integer port) { String errMsg; String fmt = "(address=\"%s\", port=%s)"; String ipOut = (ipAddress == null) ? "null" : ipAddress; String portOut = (port == null) ? "null" : port.toString(); String ipMsg = String.format(fmt, ipOut, portOut); if (ipAddress == null || port == null) { errMsg = String.format("ipAddress or port cann not be null. %s", ipMsg); throw new RuntimeException(errMsg); } if (IPUtils.isValidIpv4String(ipAddress)) { return String.format("%s:%d", ipAddress, port); } if (IPUtils.isValidIpv6String(ipAddress)) { return String.format("[%s]:%d", ipAddress, port); } if (ipAddress.matches(".*[a-zA-Z]+.*")) { return String.format("%s:%d", ipAddress, port); } errMsg = String.format("Cannot create string for ip address and port. %s", ipMsg); throw new RuntimeException(errMsg); }  static String createZeusIpString(String ipAddress, Integer port); static boolean isNetworkConnectionException(Exception ex); }
IpHelper { public static String createZeusIpString(String ipAddress, Integer port) { String errMsg; String fmt = "(address=\"%s\", port=%s)"; String ipOut = (ipAddress == null) ? "null" : ipAddress; String portOut = (port == null) ? "null" : port.toString(); String ipMsg = String.format(fmt, ipOut, portOut); if (ipAddress == null || port == null) { errMsg = String.format("ipAddress or port cann not be null. %s", ipMsg); throw new RuntimeException(errMsg); } if (IPUtils.isValidIpv4String(ipAddress)) { return String.format("%s:%d", ipAddress, port); } if (IPUtils.isValidIpv6String(ipAddress)) { return String.format("[%s]:%d", ipAddress, port); } if (ipAddress.matches(".*[a-zA-Z]+.*")) { return String.format("%s:%d", ipAddress, port); } errMsg = String.format("Cannot create string for ip address and port. %s", ipMsg); throw new RuntimeException(errMsg); }  static String createZeusIpString(String ipAddress, Integer port); static boolean isNetworkConnectionException(Exception ex);  }