ByteArrays { public static String toHexString(byte value, String separator) { return toHexString(toByteArray(value), separator); } private  ByteArrays(); static byte[] reverse(byte[] array); static byte getByte(byte[] array, int offset); static byte[] toByteArray(byte value); static String toHexString(byte value, String separator); static short getShort(byte[] array, int offset); static short getShort(byte[] array, int offset, ByteOrder bo); static byte[] toByteArray(short value); static byte[] toByteArray(short value, ByteOrder bo); static String toHexString(short value, String separator); static String toHexString(short value, String separator, ByteOrder bo); static int getInt(byte[] array, int offset); static int getInt(byte[] array, int offset, ByteOrder bo); static int getInt(byte[] array, int offset, int length); static int getInt(byte[] array, int offset, int length, ByteOrder bo); static byte[] toByteArray(int value); static byte[] toByteArray(int value, ByteOrder bo); static byte[] toByteArray(int value, int length); static byte[] toByteArray(int value, int length, ByteOrder bo); static String toHexString(int value, String separator); static String toHexString(int value, String separator, ByteOrder bo); static long getLong(byte[] array, int offset); static long getLong(byte[] array, int offset, ByteOrder bo); static byte[] toByteArray(long value); static byte[] toByteArray(long value, ByteOrder bo); static String toHexString(long value, String separator); static String toHexString(long value, String separator, ByteOrder bo); static MacAddress getMacAddress(byte[] array, int offset); static MacAddress getMacAddress(byte[] array, int offset, ByteOrder bo); static byte[] toByteArray(MacAddress value); static byte[] toByteArray(MacAddress value, ByteOrder bo); static LinkLayerAddress getLinkLayerAddress(byte[] array, int offset, int length); static LinkLayerAddress getLinkLayerAddress(
      byte[] array, int offset, int length, ByteOrder bo); static byte[] toByteArray(LinkLayerAddress value); static byte[] toByteArray(LinkLayerAddress value, ByteOrder bo); static Inet4Address getInet4Address(byte[] array, int offset); static Inet4Address getInet4Address(byte[] array, int offset, ByteOrder bo); static byte[] parseInet4Address(String addr); static Inet6Address getInet6Address(byte[] array, int offset); static Inet6Address getInet6Address(byte[] array, int offset, ByteOrder bo); static byte[] toByteArray(InetAddress value); static byte[] toByteArray(InetAddress value, ByteOrder bo); static byte[] getSubArray(byte[] array, int offset, int length); static byte[] getSubArray(byte[] array, int offset); static String toHexString(byte[] array, String separator); static String toHexString(byte[] array, String separator, int offset, int length); static short calcChecksum(byte[] data); static int calcCrc32Checksum(byte[] data); static int calcCrc32cChecksum(byte[] data); static int calcAdler32Checksum(byte[] data); static byte[] parseByteArray(String hexString, String separator); static byte[] clone(byte[] array); static void validateBounds(byte[] arr, int offset, int len); static byte[] xor(byte[] arr1, byte[] arr2); static byte[] concatenate(byte[] arr1, byte[] arr2); static byte[] concatenate(List<byte[]> arrs); static final int BYTE_SIZE_IN_BYTES; static final int SHORT_SIZE_IN_BYTES; static final int INT_SIZE_IN_BYTES; static final int LONG_SIZE_IN_BYTES; static final int INET4_ADDRESS_SIZE_IN_BYTES; static final int INET6_ADDRESS_SIZE_IN_BYTES; static final int BYTE_SIZE_IN_BITS; }
@Test public void testToHexString() throws Exception { byte[] arr = new byte[] { (byte) 0x0, (byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 0x4, (byte) 0x55, (byte) 0x56, (byte) 0x57, (byte) 0x58, (byte) 0x59, (byte) 0xaa, (byte) 0xab, (byte) 0xac, (byte) 0xad, (byte) 0xae, (byte) 0xaf, (byte) 0xfa, (byte) 0xfb, (byte) 0xfc, (byte) 0xfd, (byte) 0xfe, (byte) 0xff }; assertEquals( "00:01:02:03:04:55:56:57:58:59:aa:ab:ac:ad:ae:af:fa:fb:fc:fd:fe:ff", ByteArrays.toHexString(arr, ":")); assertEquals( "00 : 01 : 02 : 03 : 04 : 55 : 56 : 57 : 58 : 59 : aa : ab : ac : ad : ae : af : fa : fb : fc : fd : fe : ff", ByteArrays.toHexString(arr, " : ")); assertEquals("55-56-57-58-59", ByteArrays.toHexString(arr, "-", 5, 5)); assertEquals("aaabacadaeaf", ByteArrays.toHexString(arr, "", 10, 6)); }