ByteUtils { public static byte[] paddingZeroOnTail(byte[] input, int byteLength) { if (input.length > byteLength) { throw new IllegalArgumentException("input byte array must have length which is less than byteLength you want to be."); } byte[] padding = new byte[byteLength - input.length]; return join(input, padding); }  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_PaddingTailZeroArray() { byte[] input = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; byte[] result = ByteUtils.paddingZeroOnTail(input, 10); byte[] result2 = ByteUtils.paddingZeroOnTail(input, 20); assertThat(result, is(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 0, 0})); assertThat(result2, is(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})); }
@Test(expected = IllegalArgumentException.class) public void failure_PaddingTailZeroArray() { byte[] input = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; ByteUtils.paddingZeroOnTail(input, 5); ByteUtils.paddingZeroOnTail(input, 2); }