src/main/java/org/jcodec/containers/mkv/util/EbmlUtil.java
public static byte[] ebmlEncodeLen(long value, int length) {
        byte[] b = new byte[length];
        for (int idx = 0; idx < length; idx++) {
            // Rightmost bytes should go to end of array to preserve big-endian notation
            b[length - idx - 1] = (byte) ((value >>> (8 * idx)) & 0xFFL);
        }

        b[0] |= 0x80 >>> (length - 1);
        return b;
    }
public static byte[] ebmlEncodeLen(long value, int length) {
        byte[] b = new byte[length];
        for (int idx = 0; idx < length; idx++) {
            // Rightmost bytes should go to end of array to preserve big-endian notation
            b[length - idx - 1] = (byte) ((value >>> (8 * idx)) & 0xFFL);
        }

        b[0] |= 0x80 >>> (length - 1);
        return b;
    }
Encodes unsigned integer with given length

@param value
unsigned integer to be encoded
@param length
ebml sequence length
@return