@Test public void testByteArrayToHex() { assertEquals("00", ByteAdapter.byteArrayToHexString(new byte[] {0})); assertEquals("01", ByteAdapter.byteArrayToHexString(new byte[] {1}) ); assertEquals("0C", ByteAdapter.byteArrayToHexString(new byte[] {12})); assertEquals("01020304", ByteAdapter.byteArrayToHexString(new byte[] {1, 2, 3, 4})); assertEquals("00010004", ByteAdapter.byteArrayToHexString(new byte[] {0, 1, 0, 4})); assertEquals("0C0F000107090B",ByteAdapter.byteArrayToHexString(new byte[] {12, 15, 0, 1, 7, 9, 11})); assertEquals("641F032F160978", ByteAdapter.byteArrayToHexString(new byte[] {100, 31, 3, 47, 22, 9, 120})); }
public static String byteArrayToHexString(byte[] bytes) { if(bytes == null) { return ""; } char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } return new String(hexChars); }
ByteAdapter extends TypeAdapter<byte[]> { public static String byteArrayToHexString(byte[] bytes) { if(bytes == null) { return ""; } char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } return new String(hexChars); } }
ByteAdapter extends TypeAdapter<byte[]> { public static String byteArrayToHexString(byte[] bytes) { if(bytes == null) { return ""; } char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } return new String(hexChars); }  }
ByteAdapter extends TypeAdapter<byte[]> { public static String byteArrayToHexString(byte[] bytes) { if(bytes == null) { return ""; } char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } return new String(hexChars); }  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 String byteArrayToHexString(byte[] bytes) { if(bytes == null) { return ""; } char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } return new String(hexChars); }  byte[] read(JsonReader reader); void write(JsonWriter writer, byte[] bytes); static String byteArrayToHexString(byte[] bytes); static byte[] hexStringToByteArray(String s);  }