public static byte[] toByteArray(long value, int length) {
        final byte[] buffer = ByteBuffer.allocate(8).putLong(value).array();
        for (int i = 0; i < 8 - length; i++) {
            if (buffer[i] != 0) {
                throw new IllegalArgumentException(
                    "Value is does not fit into byte array " + (8 - i) + " > " + length);
            }
        }
        return adjustLength(buffer, length);
    }
@Test
    public void toByteArrayBigIntegerShouldRemove() {
        thrown.expect(IllegalArgumentException.class);
        thrown.expectMessage("Value is does not fit into byte array 9 > 8");
        assertArrayEquals(new byte[] { 2 }, ByteArrayUtils.toByteArray(BigInteger.valueOf(0x102L), 1));
    }