### Question:
HexUtil { public static String toHexFromBytes(final ByteBuffer bytes) { if (bytes == null) { return ""; } StringBuilder hexBuffer = new StringBuilder(); while (bytes.hasRemaining()) { hexBuffer.append(toHexFromByte(bytes.get())); } return hexBuffer.toString(); }  static String toHexFromByte(final byte b); static byte toByteFromHex(char upperChar, char lowerChar); static String toHexFromBytes(final ByteBuffer bytes); static String toHexFromBytes(final byte[] bytes); static byte[] toBytesFromHex(String hexStr); final static int BITS_PER_HEX_DIGIT; }### Answer:
@Test public void testHexToBytes() { byte[] bytes = { (byte)0x0a, (byte)0xff, (byte)0x12, (byte)0x38, (byte)0xde, (byte)0xad, (byte)0xbe, (byte)0xef, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xde, (byte)0xad, (byte)0xc0, (byte)0xde }; Assert.assertEquals("0aff1238deadbeef00000000deadc0de", HexUtil.toHexFromBytes(bytes)); Assert.assertEquals("", HexUtil.toHexFromBytes(new byte[] {})); Assert.assertEquals("", HexUtil.toHexFromBytes((byte[])null)); Assert.assertEquals("01", HexUtil.toHexFromBytes(new byte[] { (byte) 0x01 })); ByteBuffer bb = ByteBuffer.wrap(bytes); Assert.assertEquals("0aff1238deadbeef00000000deadc0de", HexUtil.toHexFromBytes(bb)); Assert.assertEquals("", HexUtil.toHexFromBytes(ByteBuffer.wrap(new byte[] {}))); Assert.assertEquals("", HexUtil.toHexFromBytes((ByteBuffer)null)); Assert.assertEquals("01", HexUtil.toHexFromBytes(ByteBuffer.wrap(new byte[] { (byte) 0x01 }))); }