ConvertionUtils { public static String toHex(byte[] bytes) { if (bytes == null || bytes.length == 0) { return ""; } StringBuilder r = new StringBuilder(bytes.length * 2); for (byte b : bytes) { r.append(hexCode[(b >> 4) & 0xF]); r.append(hexCode[(b & 0xF)]); } return r.toString(); }  static byte[] base64ToBytes(String value); static String base64ToString(byte[] bytes); static String base64ToString(String value); static byte[] captureSnapshot(Object snapshotModel); static byte[] concatenate(byte[] first, byte[] second); static T deserializeFromJson(String serializedObject, Class<T> objectType); static Map<String, String> deserializeMapFromJson(String serializedObject); static synchronized Gson getGson(); static byte[] hexToBytes(String value); static T parseSnapshot(byte[] snapshot, Class<T> objectType); static String serializeToJson(Object serializable); static byte[] toBase64Bytes(String value); static String toBase64String(byte[] bytes); static String toBase64String(String value); static byte[] toBytes(String string); static String toHex(byte[] bytes); static String toString(byte[] bytes); static String toString(byte[] inputBytes, StringEncoding encoding); static String toString(InputStream is);  }
@Test public void toHex() { byte[] bytes = ConvertionUtils.toBytes(TEXT); String str = ConvertionUtils.toHex(bytes); bytes = ConvertionUtils.hexToBytes(str); str = ConvertionUtils.toString(bytes); assertEquals(TEXT, str); }