/** * Decodes data encoded using {@link #toHex(byte[],int,int) toHex}. * * @param hex data to be converted * @param start offset * @param len count * @throws IOException if input does not represent hex encoded value * @since 1.29 */ public static byte[] fromHex(char[] hex, int start, int len) throws IOException { if (hex == null) throw new IOException("null"); int i = hex.length; if (i % 2 != 0) throw new IOException("odd length"); byte[] magic = new byte[i / 2]; for (; i > 0; i -= 2) { String g = new String(hex, i - 2, 2); try { magic[(i / 2) - 1] = (byte) Integer.parseInt(g, 16); } catch (NumberFormatException ex) { throw new IOException(ex.getLocalizedMessage()); } } return magic; }