### Question:
NetUtil { public static byte[] createByteArrayFromIpAddressString( String ipAddressString) { if (isValidIpV4Address(ipAddressString)) { StringTokenizer tokenizer = new StringTokenizer(ipAddressString, "."); String token; int tempInt; byte[] byteAddress = new byte[4]; for (int i = 0; i < 4; i++) { token = tokenizer.nextToken(); tempInt = Integer.parseInt(token); byteAddress[i] = (byte) tempInt; } return byteAddress; } if (isValidIpV6Address(ipAddressString)) { if (ipAddressString.charAt(0) == '[') { ipAddressString = ipAddressString.substring(1, ipAddressString .length() - 1); } StringTokenizer tokenizer = new StringTokenizer(ipAddressString, ":.", true); ArrayList<String> hexStrings = new ArrayList<String>(); ArrayList<String> decStrings = new ArrayList<String>(); String token = ""; String prevToken = ""; int doubleColonIndex = -1; while (tokenizer.hasMoreTokens()) { prevToken = token; token = tokenizer.nextToken(); if (":".equals(token)) { if (":".equals(prevToken)) { doubleColonIndex = hexStrings.size(); } else if (prevToken.length() > 0) { hexStrings.add(prevToken); } } else if (".".equals(token)) { decStrings.add(prevToken); } } if (":".equals(prevToken)) { if (":".equals(token)) { doubleColonIndex = hexStrings.size(); } else { hexStrings.add(token); } } else if (".".equals(prevToken)) { decStrings.add(token); } int hexStringsLength = 8; if (!decStrings.isEmpty()) { hexStringsLength -= 2; } if (doubleColonIndex != -1) { int numberToInsert = hexStringsLength - hexStrings.size(); for (int i = 0; i < numberToInsert; i++) { hexStrings.add(doubleColonIndex, "0"); } } byte[] ipByteArray = new byte[16]; for (int i = 0; i < hexStrings.size(); i++) { convertToBytes(hexStrings.get(i), ipByteArray, i * 2); } for (int i = 0; i < decStrings.size(); i++) { ipByteArray[i + 12] = (byte) (Integer.parseInt(decStrings .get(i)) & 255); } return ipByteArray; } return null; } private  NetUtil(); static byte[] createByteArrayFromIpAddressString(
            String ipAddressString); static boolean isValidIpV6Address(String ipAddress); static boolean isValidIp4Word(String word); static boolean isValidIpV4Address(String value);  }### Answer:
@Test public void testCreateByteArrayFromIpAddressString() { for (Entry<String, byte[]> stringEntry : validIpV4Hosts.entrySet()) { assertArrayEquals(stringEntry.getValue(), NetUtil.createByteArrayFromIpAddressString(stringEntry.getKey())); } for (Entry<String, byte[]> stringEntry : invalidIpV4Hosts.entrySet()) { assertArrayEquals(stringEntry.getValue(), NetUtil.createByteArrayFromIpAddressString(stringEntry.getKey())); } for (Entry<String, byte[]> stringEntry : validIpV6Hosts.entrySet()) { assertArrayEquals(stringEntry.getValue(), NetUtil.createByteArrayFromIpAddressString(stringEntry.getKey())); } for (Entry<String, byte[]> stringEntry : invalidIpV6Hosts.entrySet()) { assertArrayEquals(stringEntry.getValue(), NetUtil.createByteArrayFromIpAddressString(stringEntry.getKey())); } }