ByteUtil { public static String bytesToHex(byte[] bytes) { 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); }  static void debugFrame(Logger logger, String message, ByteBuf byteIn); static String formatGroup(String str, int groupSize, int lineBreak); static String maxString(String value, int size); static String bytesToHex(byte[] bytes); static String debugByteArray(byte[] byteArray); static String byteToChar(byte value); static String bytesToHex(byte[] bytes, int groupSize); static String toSimpleString(byte[] bytes); static final byte[] intToBytes(int value); static int bytesToInt(byte[] b); static byte[] longToBytes(long value); static void longToBytes(long x, byte[] output, int offset); static byte[] doubleLongToBytes(long value1, long value2); static byte[] hexToBytes(String hexStr); static String readLine(ActiveMQBuffer buffer); static long convertTextBytes(final String text); static boolean equals(final byte[] left, final byte[] right); static boolean equals(final byte[] left,
                                final byte[] right,
                                final int rightOffset,
                                final int rightLength); static boolean equals(final byte[] bytes, final ByteBuf byteBuf, final int offset, final int length); static int intFromBytes(byte b1, byte b2, byte b3, byte b4); static void zeros(final ByteBuffer buffer); static void zeros(final ByteBuffer buffer, int offset, int bytes); static String getHumanReadableByteCount(long bytes); static final String NON_ASCII_STRING; }
@Test public void testBytesToString() { byte[] byteArray = new byte[]{0, 1, 2, 3}; testEquals("0001 0203", ByteUtil.bytesToHex(byteArray, 2)); testEquals("00 01 02 03", ByteUtil.bytesToHex(byteArray, 1)); testEquals("000102 03", ByteUtil.bytesToHex(byteArray, 3)); }