@Test(expected = IllegalArgumentException.class) public void testMakeConnDesc_ipv6_invalidAddress() throws Exception { ConnectionDescriptor .makeConnDesc("[0000:0Z00:0000:0000:0000:0acf:0000:0001]:9000"); }
public static ConnectionDescriptor makeConnDesc(String address) { if (address == null || address.trim().length() == 0) { throw new IllegalArgumentException(String.format(ERR_MSG, "The given address is empty")); } address = address.replaceFirst("^tcp: if (address.startsWith("unix: final String path = address.substring("unix: if (path.isEmpty()) { throw new IllegalArgumentException( "Unix socket file name is empty."); } final File f = new File(path); if (!f.getAbsolutePath().matches("^[^*&%\\s]+$")) { throw new IllegalArgumentException(String.format(ERR_MSG,"Not a regular file name : " + f.getAbsolutePath())); } return new UnixSocketConnectionDescriptor(path); } final Matcher ipv4Matcher = PATTERN_HOSTNAME_PORT.matcher(address); final Matcher ipv6Matcher = PATTERN_IPV6_PORT.matcher(address); if (ipv4Matcher.matches()) { try { final InetAddress addr = InetAddress.getByName(ipv4Matcher .group(1)); final int port = Integer.parseInt(ipv4Matcher.group(2)); return new TcpConnectionDescriptor(addr, port); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } } else if (ipv6Matcher.matches()) { try { final InetAddress addr = InetAddress.getByName(ipv6Matcher .group(1)); final int port = Integer.parseInt(ipv6Matcher.group(2)); return new TcpConnectionDescriptor(addr, port); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException(String.format(ERR_MSG, "Not a valid address")); } }
ConnectionDescriptor { public static ConnectionDescriptor makeConnDesc(String address) { if (address == null || address.trim().length() == 0) { throw new IllegalArgumentException(String.format(ERR_MSG, "The given address is empty")); } address = address.replaceFirst("^tcp: if (address.startsWith("unix: final String path = address.substring("unix: if (path.isEmpty()) { throw new IllegalArgumentException( "Unix socket file name is empty."); } final File f = new File(path); if (!f.getAbsolutePath().matches("^[^*&%\\s]+$")) { throw new IllegalArgumentException(String.format(ERR_MSG,"Not a regular file name : " + f.getAbsolutePath())); } return new UnixSocketConnectionDescriptor(path); } final Matcher ipv4Matcher = PATTERN_HOSTNAME_PORT.matcher(address); final Matcher ipv6Matcher = PATTERN_IPV6_PORT.matcher(address); if (ipv4Matcher.matches()) { try { final InetAddress addr = InetAddress.getByName(ipv4Matcher .group(1)); final int port = Integer.parseInt(ipv4Matcher.group(2)); return new TcpConnectionDescriptor(addr, port); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } } else if (ipv6Matcher.matches()) { try { final InetAddress addr = InetAddress.getByName(ipv6Matcher .group(1)); final int port = Integer.parseInt(ipv6Matcher.group(2)); return new TcpConnectionDescriptor(addr, port); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException(String.format(ERR_MSG, "Not a valid address")); } } }
ConnectionDescriptor { public static ConnectionDescriptor makeConnDesc(String address) { if (address == null || address.trim().length() == 0) { throw new IllegalArgumentException(String.format(ERR_MSG, "The given address is empty")); } address = address.replaceFirst("^tcp: if (address.startsWith("unix: final String path = address.substring("unix: if (path.isEmpty()) { throw new IllegalArgumentException( "Unix socket file name is empty."); } final File f = new File(path); if (!f.getAbsolutePath().matches("^[^*&%\\s]+$")) { throw new IllegalArgumentException(String.format(ERR_MSG,"Not a regular file name : " + f.getAbsolutePath())); } return new UnixSocketConnectionDescriptor(path); } final Matcher ipv4Matcher = PATTERN_HOSTNAME_PORT.matcher(address); final Matcher ipv6Matcher = PATTERN_IPV6_PORT.matcher(address); if (ipv4Matcher.matches()) { try { final InetAddress addr = InetAddress.getByName(ipv4Matcher .group(1)); final int port = Integer.parseInt(ipv4Matcher.group(2)); return new TcpConnectionDescriptor(addr, port); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } } else if (ipv6Matcher.matches()) { try { final InetAddress addr = InetAddress.getByName(ipv6Matcher .group(1)); final int port = Integer.parseInt(ipv6Matcher.group(2)); return new TcpConnectionDescriptor(addr, port); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException(String.format(ERR_MSG, "Not a valid address")); } }  }
ConnectionDescriptor { public static ConnectionDescriptor makeConnDesc(String address) { if (address == null || address.trim().length() == 0) { throw new IllegalArgumentException(String.format(ERR_MSG, "The given address is empty")); } address = address.replaceFirst("^tcp: if (address.startsWith("unix: final String path = address.substring("unix: if (path.isEmpty()) { throw new IllegalArgumentException( "Unix socket file name is empty."); } final File f = new File(path); if (!f.getAbsolutePath().matches("^[^*&%\\s]+$")) { throw new IllegalArgumentException(String.format(ERR_MSG,"Not a regular file name : " + f.getAbsolutePath())); } return new UnixSocketConnectionDescriptor(path); } final Matcher ipv4Matcher = PATTERN_HOSTNAME_PORT.matcher(address); final Matcher ipv6Matcher = PATTERN_IPV6_PORT.matcher(address); if (ipv4Matcher.matches()) { try { final InetAddress addr = InetAddress.getByName(ipv4Matcher .group(1)); final int port = Integer.parseInt(ipv4Matcher.group(2)); return new TcpConnectionDescriptor(addr, port); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } } else if (ipv6Matcher.matches()) { try { final InetAddress addr = InetAddress.getByName(ipv6Matcher .group(1)); final int port = Integer.parseInt(ipv6Matcher.group(2)); return new TcpConnectionDescriptor(addr, port); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException(String.format(ERR_MSG, "Not a valid address")); } }  static ConnectionDescriptor makeConnDesc(String address); abstract ISocket makeSocket(); }
ConnectionDescriptor { public static ConnectionDescriptor makeConnDesc(String address) { if (address == null || address.trim().length() == 0) { throw new IllegalArgumentException(String.format(ERR_MSG, "The given address is empty")); } address = address.replaceFirst("^tcp: if (address.startsWith("unix: final String path = address.substring("unix: if (path.isEmpty()) { throw new IllegalArgumentException( "Unix socket file name is empty."); } final File f = new File(path); if (!f.getAbsolutePath().matches("^[^*&%\\s]+$")) { throw new IllegalArgumentException(String.format(ERR_MSG,"Not a regular file name : " + f.getAbsolutePath())); } return new UnixSocketConnectionDescriptor(path); } final Matcher ipv4Matcher = PATTERN_HOSTNAME_PORT.matcher(address); final Matcher ipv6Matcher = PATTERN_IPV6_PORT.matcher(address); if (ipv4Matcher.matches()) { try { final InetAddress addr = InetAddress.getByName(ipv4Matcher .group(1)); final int port = Integer.parseInt(ipv4Matcher.group(2)); return new TcpConnectionDescriptor(addr, port); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } } else if (ipv6Matcher.matches()) { try { final InetAddress addr = InetAddress.getByName(ipv6Matcher .group(1)); final int port = Integer.parseInt(ipv6Matcher.group(2)); return new TcpConnectionDescriptor(addr, port); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } } else { throw new IllegalArgumentException(String.format(ERR_MSG, "Not a valid address")); } }  static ConnectionDescriptor makeConnDesc(String address); abstract ISocket makeSocket();  }