@Test public void testHexToByteArray() { assertTrue(Arrays.equals(ByteAdapter.hexStringToByteArray("00"), new byte[] {0})); assertTrue(Arrays.equals(ByteAdapter.hexStringToByteArray("01"), new byte[] {1})); assertTrue(Arrays.equals(ByteAdapter.hexStringToByteArray("0C"), new byte[] {12})); assertTrue(Arrays.equals(ByteAdapter.hexStringToByteArray("01020304"), new byte[] {1, 2, 3, 4})); assertTrue(Arrays.equals(ByteAdapter.hexStringToByteArray("00010004"), new byte[] {0, 1, 0, 4})); assertTrue(Arrays.equals(ByteAdapter.hexStringToByteArray("0C0F000107090B"), new byte[] {12, 15, 0, 1, 7, 9, 11})); assertTrue(Arrays.equals(ByteAdapter.hexStringToByteArray("641F032F160978"), new byte[] {100, 31, 3, 47, 22, 9, 120})); }
public static byte[] hexStringToByteArray(String s) { int length = s.length(); byte[] data = new byte[length / 2]; for (int i = 0; i < length; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16)); } return data; }
ByteAdapter extends TypeAdapter<byte[]> { public static byte[] hexStringToByteArray(String s) { int length = s.length(); byte[] data = new byte[length / 2]; for (int i = 0; i < length; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16)); } return data; } }
ByteAdapter extends TypeAdapter<byte[]> { public static byte[] hexStringToByteArray(String s) { int length = s.length(); byte[] data = new byte[length / 2]; for (int i = 0; i < length; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16)); } return data; }  }
ByteAdapter extends TypeAdapter<byte[]> { public static byte[] hexStringToByteArray(String s) { int length = s.length(); byte[] data = new byte[length / 2]; for (int i = 0; i < length; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16)); } return data; }  byte[] read(JsonReader reader); void write(JsonWriter writer, byte[] bytes); static String byteArrayToHexString(byte[] bytes); static byte[] hexStringToByteArray(String s); }
ByteAdapter extends TypeAdapter<byte[]> { public static byte[] hexStringToByteArray(String s) { int length = s.length(); byte[] data = new byte[length / 2]; for (int i = 0; i < length; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16)); } return data; }  byte[] read(JsonReader reader); void write(JsonWriter writer, byte[] bytes); static String byteArrayToHexString(byte[] bytes); static byte[] hexStringToByteArray(String s);  }