ByteUtils { public static byte[] concatenate(byte[] x, byte[] y) { if (x == null) { return y; } if (y == null) { return x; } byte[] ret = new byte[x.length + y.length]; System.arraycopy(x, 0, ret, 0, x.length); System.arraycopy(y, 0, ret, x.length, y.length); return ret; }  static byte[] clone(@Nullable byte[] input); static byte[] concatenate(byte[] x, byte[] y); static byte[] concatenate(byte x, byte[] y); static byte[] concatenate(byte[] x, byte y); static byte[] concatenate(byte x, byte y); static byte[] cutLeadingNullBytes(byte[] input); static byte[] cutLeadingNullByte(byte[] input); static byte[] copy(byte[] input, int offset, int length); static boolean compare(byte[] x, byte[] y); static boolean compare(byte x, byte[] y); static boolean compare(byte[] x, byte y); static boolean compare(byte x, byte y); static boolean isPrefix(byte[] prefix, byte[] data); static boolean isPrefix(byte prefix, byte[] data); static byte[] reverse(byte[] in); static String toHexString(@Nullable byte[] bytes); static String toHexString(@Nullable byte[] bytes, boolean formatted); static String toHexString(@Nullable byte[] bytes, boolean formatted, boolean addLinebreak); static String toFileSafeBase64String(@Nullable byte[] bytes); static String toWebSafeBase64String(@Nullable byte[] bytes); static String toFileSafeBase64String(@Nullable byte[] bytes, boolean withPadding); static short toShort(byte[] bytes); static short toShort(byte[] bytes, boolean bigEndian); static int toInteger(byte[] bytes); static int toInteger(byte[] bytes, boolean bigEndian); static long toLong(byte[] bytes); static long toLong(byte[] bytes, boolean bigEndian); static boolean isBitSet(int position, byte[] array); static void setBit(int position, byte[] array);  }
@Test public void testConcatenate() { byte[] a = new byte[] { 0x00, 0x01, 0x02 }, b = new byte[] { 0x03, 0x04, 0x05 }; byte c = 6, d = 7; byte[] result = ByteUtils.concatenate(a, b); byte[] expected = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; assertEquals(expected, result); result = ByteUtils.concatenate(a, c); expected = new byte[] { 0x00, 0x01, 0x02, 0x06 }; assertEquals(expected, result); result = ByteUtils.concatenate(d, b); expected = new byte[] { 0x07, 0x03, 0x04, 0x05 }; assertEquals(expected, result); result = ByteUtils.concatenate(d, c); expected = new byte[] { 0x07, 0x06 }; assertEquals(expected, result); result = ByteUtils.concatenate(d, null); expected = new byte[] { 0x07 }; assertEquals(expected, result); result = ByteUtils.concatenate(null, d); expected = new byte[] { 0x07 }; assertEquals(expected, result); }