ByteUtils { public static byte[][] split(byte[] input, int firstLength) { if (input.length < firstLength) { throw new ArrayIndexOutOfBoundsException("Specified index over input length"); } byte[] first = new byte[firstLength]; byte[] second = new byte[input.length - firstLength]; System.arraycopy(input, 0, first, 0, firstLength); System.arraycopy(input, firstLength, second, 0, input.length - firstLength); return new byte[][]{first, second}; }  static byte[][] split(byte[] input, int firstLength); static byte[] reverse(byte[] input); static byte[] join(byte[] value1, byte[] value2); static byte[] join(byte[]... inputs); static byte[] paddingZeroOnHead(byte[] input, int byteLength); static byte[] paddingZeroOnTail(byte[] input, int byteLength); static int readBit(byte value, int position);  }
@Test public void success_SplitByteArray() { byte[] input = new byte[]{32, 43, 53, 56, 34, 23, 43, 93, 42, 42}; byte[][] result = ByteUtils.split(input, 5); assertThat(result[0], is(new byte[]{32, 43, 53, 56, 34})); assertThat(result[1], is(new byte[]{23, 43, 93, 42, 42})); }
@Test(expected = ArrayIndexOutOfBoundsException.class) public void failure_SplitByteArray() { byte[] input = new byte[]{32, 43, 53, 56, 34, 23, 43}; ByteUtils.split(input, 8); }