Util { public static byte[] addressToBytes(String address) throws UserErrorException { Matcher m = IPv4_FORMAT.matcher(address); if (m.find()) { byte[] result = new byte[4]; String b = m.group(1); result[0] = (byte)Integer.parseInt(b); b = m.group(2); result[1] = (byte)Integer.parseInt(b); b = m.group(3); result[2] = (byte)Integer.parseInt(b); b = m.group(4); result[3] = (byte)Integer.parseInt(b); return result; } return null; } private  Util(); static byte[] addressToBytes(String address); static boolean identical(byte[] b, byte[] b2); static void validatePort(int port); static InetSocketAddress computeLocalEndpoint(
            NetworkInterface ni, InetAddress localAddress, Integer localPort, InetAddress address, Integer port); static boolean isIPv4(InetAddress a); static boolean isIPv6(InetAddress a); static String inetAddressToString(InetAddress a); static void displayInfo(); static void dumpState(Configuration c, DatagramSocket s, DatagramPacket p); static String truncate(byte[] payload, int length); static final Pattern IPv4_FORMAT; }
@Test public void addressToBytes_NoConversion() throws Exception { byte[] b = Util.addressToBytes("something"); assertNull(b); }
@Test public void addressToBytes() throws Exception { byte[] b = Util.addressToBytes("127.0.0.1"); assertNotNull(b); assertEquals(4, b.length); assertEquals(127, b[0]); assertEquals(0, b[1]); assertEquals(0, b[2]); assertEquals(1, b[3]); }