StringUtils { @NotNull public static String convertBytesToHex(@NotNull byte[] value) { checkNotNull(value); int len = value.length; char[] buff = new char[len + len]; char[] hex = HEX; for (int i = 0; i < len; i++) { int c = value[i] & 0xff; buff[i + i] = hex[c >> 4]; buff[i + i + 1] = hex[c & 0xf]; } return new String(buff); } private  StringUtils(); @NotNull static String convertBytesToHex(@NotNull byte[] value); @NotNull static byte[] convertHexToBytes(@NotNull String s); static int estimateMemoryUsage(String s);  }
@Test public void testBytesToHex() { assertEquals("0123", StringUtils.convertBytesToHex(new byte[] {(byte) 0x01, (byte) 0x23})); assertEquals("89bd", StringUtils.convertBytesToHex(new byte[] {(byte) 0x89, (byte) 0xbd})); assertEquals("face", StringUtils.convertBytesToHex(new byte[] {(byte) 0xfa, (byte) 0xce})); assertEquals("", StringUtils.convertBytesToHex(new byte[] {})); }
@Test(expected = NullPointerException.class) public void testNullToHex() { StringUtils.convertBytesToHex(null); }