/** * Convert the given hex string with ":" inserted into a byte array. * * <ul> * <li>{@code null} is returned if {@code null} is passed.</li> * <li>An empty byte array is returned if an empty string is passed.</li> * </ul> * * @param hex A hex string with ":" inserted. * @return A byte array. * @throws NumberFormatException * The given string is not a hex string. */ public static byte[] toBytes(String hex) { if (hex == null) { return null; } if (hex.isEmpty()) { return new byte[0]; } String[] octets = hex.split(HEX_SEPARATOR); byte[] bytes = new byte[octets.length]; for (int i = 0; i < octets.length; i++) { bytes[i] = (byte)parseHexOctet(octets[i]); } return bytes; }
if (c == ByteUtils.HEX_SEPARATOR_CHAR) { count++; int octet = ByteUtils.parseHexOctet(builder.toString()); value = (value << Byte.SIZE) | (long)octet; builder = new StringBuilder(); int octet = ByteUtils.parseHexOctet(builder.toString()); return (value << Byte.SIZE) | (long)octet;