@Test(groups = "io", dataProvider = "invalid-decode") public void decodeException(final char[] data) throws Exception { try { Hex.decode(data); Assert.fail("Should have thrown exception"); } catch (Exception e) { Assert.assertEquals(IllegalArgumentException.class, e.getClass()); } }
public static byte[] decode(final char... value) { if (value == null) { return null; } final int l = value.length; if ((l & 0x01) != 0) { throw new IllegalArgumentException( String.format("Cannot decode odd number of characters for %s", String.valueOf(value))); } final byte[] decoded = new byte[l >> 1]; for (int i = 0, j = 0; j < l; i++, j += 2) { final int high = decode(value, j) << 4; final int low = decode(value, j + 1); decoded[i] = (byte) ((high | low) & 0xFF); } return decoded; }
Hex { public static byte[] decode(final char... value) { if (value == null) { return null; } final int l = value.length; if ((l & 0x01) != 0) { throw new IllegalArgumentException( String.format("Cannot decode odd number of characters for %s", String.valueOf(value))); } final byte[] decoded = new byte[l >> 1]; for (int i = 0, j = 0; j < l; i++, j += 2) { final int high = decode(value, j) << 4; final int low = decode(value, j + 1); decoded[i] = (byte) ((high | low) & 0xFF); } return decoded; } }
Hex { public static byte[] decode(final char... value) { if (value == null) { return null; } final int l = value.length; if ((l & 0x01) != 0) { throw new IllegalArgumentException( String.format("Cannot decode odd number of characters for %s", String.valueOf(value))); } final byte[] decoded = new byte[l >> 1]; for (int i = 0, j = 0; j < l; i++, j += 2) { final int high = decode(value, j) << 4; final int low = decode(value, j + 1); decoded[i] = (byte) ((high | low) & 0xFF); } return decoded; } private  Hex(); }
Hex { public static byte[] decode(final char... value) { if (value == null) { return null; } final int l = value.length; if ((l & 0x01) != 0) { throw new IllegalArgumentException( String.format("Cannot decode odd number of characters for %s", String.valueOf(value))); } final byte[] decoded = new byte[l >> 1]; for (int i = 0, j = 0; j < l; i++, j += 2) { final int high = decode(value, j) << 4; final int low = decode(value, j + 1); decoded[i] = (byte) ((high | low) & 0xFF); } return decoded; } private  Hex(); static char[] encode(final byte... value); static byte[] decode(final char... value); }
Hex { public static byte[] decode(final char... value) { if (value == null) { return null; } final int l = value.length; if ((l & 0x01) != 0) { throw new IllegalArgumentException( String.format("Cannot decode odd number of characters for %s", String.valueOf(value))); } final byte[] decoded = new byte[l >> 1]; for (int i = 0, j = 0; j < l; i++, j += 2) { final int high = decode(value, j) << 4; final int low = decode(value, j + 1); decoded[i] = (byte) ((high | low) & 0xFF); } return decoded; } private  Hex(); static char[] encode(final byte... value); static byte[] decode(final char... value);  }