protected EBMLElement(byte[] buffer, int offset, int length) {
        
        if (length < 2) {
            throw new RuntimeException("Partial header (buffered sample too small).");
        }
        
        this.buffer = buffer;
        this.offset = offset;

        int limit = offset + length;

        long sizeFlag;
        long num;

        sizeFlag = 0x80;
        num = 0;
        while (((num |= buffer[offset++] & 0xff) & sizeFlag) == 0 && sizeFlag != 0) {
            if (offset >= limit) {
                throw new RuntimeException("Partial header (buffered sample too small).");
            }
            num <<= 8;
            sizeFlag <<= 7;
        }
        
        id = num;
        
        sizeFlag = 0x80;
        num = 0;
        while (((num |= buffer[offset++] & 0xff) & sizeFlag) == 0 && sizeFlag != 0) {
            if (offset >= limit) {
                throw new RuntimeException("Partial header (buffered sample too small).");
            }
            num <<= 8;
            sizeFlag <<= 7;
        }
        
        size = num ^ sizeFlag;
        
        dataOffset = offset;
    }