/** * This will decode the supplied value as a hex encoded string to a byte[]. Returns null if the supplied character * array is null. * * @param value to hex decode * * @return hex decoded value */ public static byte[] hexDecode(final char[] value) { return value != null ? Hex.decode(value) : null; }
/** * This will convert the supplied value to a hex encoded string. Returns null if the supplied byte array is null. * * @param value to hex encode * * @return hex encoded value */ public static char[] hexEncode(final byte[] value) { return value != null ? Hex.encode(value) : null; }
/** * @param raw data to encode * @param encoded valid encoding * * @throws Exception On test failure. */ @Test(groups = {"io"}, dataProvider = "encode-decode") public void encodeAndDecode(final byte[] raw, final String encoded) throws Exception { final char[] c = Hex.encode(raw); Assert.assertEquals(encoded.toCharArray(), c); Assert.assertEquals(raw, Hex.decode(c)); }
/** * This will decode the supplied value as a hex encoded string to a byte[]. Returns null if the supplied character * array is null. * * @param value to hex decode * * @return hex decoded value */ public static byte[] hexDecode(final char[] value) { return value != null ? Hex.decode(value) : null; }
/** * This will convert the supplied value to a hex encoded string. Returns null if the supplied byte array is null. * * @param value to hex encode * * @return hex encoded value */ public static char[] hexEncode(final byte[] value) { return value != null ? Hex.encode(value) : null; }
/** * This will decode the supplied value as a hex encoded string to a byte[]. Returns null if the supplied character * array is null. * * @param value to hex decode * * @return hex decoded value */ public static byte[] hexDecode(final char[] value) { return value != null ? Hex.decode(value) : null; }
/** * This will convert the supplied value to a hex encoded string. Returns null if the supplied byte array is null. * * @param value to hex encode * * @return hex encoded value */ public static char[] hexEncode(final byte[] value) { return value != null ? Hex.encode(value) : null; }
/** * @param data to decode * * @throws Exception On test failure. */ @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()); } } }