/** * Convert a string representation of an ethernet address into a byte * array. * * @param hex A hex string which represents an ethernet address. * @return A byte array that contains 6 octets if a valid hex string is * passed. {@code null} is returned if {@code null} is passed. * @throws IllegalArgumentException * The given string is not a string representation of an ethernet * address. */ public static byte[] toBytes(String hex) { byte[] bytes = ByteUtils.toBytes(hex); if (bytes != null) { checkAddress(bytes); } return bytes; }
/** * Parse a string representation of Ethernet address. * * @param str A string representation of Ethernet address. * @return An {@code EthernetAddress} object. * @throws BadRequestException * Invalid string is passed to {@code str}. */ protected final EthernetAddress parseEthernetAddress(String str) { try { byte[] b = ByteUtils.toBytes(str); return new EthernetAddress(b); } catch (Exception e) { throw new BadRequestException("Invalid MAC address."); } }