Encodings { public static String hex(byte[] bytes) { var values = new byte[bytes.length * 2]; int i = 0; for (byte value : bytes) { values[i++] = (byte) HEX_CHARS[value >> 4 & 0xF]; values[i++] = (byte) HEX_CHARS[value & 0xF]; } return new String(values, US_ASCII); }  static String uriComponent(String value); static String decodeURIComponent(String value); static String base64(String value); static String base64(byte[] value); static byte[] decodeBase64(String value); static String base64URLSafe(byte[] value); static byte[] decodeBase64URLSafe(String value); static String hex(byte[] bytes);  }
@Test void hex() { assertThat(Encodings.hex(new byte[]{0, 1, 0xf})).isEqualTo("00010F"); assertThat(Encodings.hex(new byte[]{-128, -1, 127})).isEqualTo("80FF7F"); assertThat(Encodings.hex(new byte[0])).isEqualTo(""); }