oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1.java [37:105]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    static final int FOOTER_SIZE = 16;

    static Buffer loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException {
        Buffer meta = reader.readAtEnd(FOOTER_SIZE, FOOTER_SIZE);

        int crc32 = meta.getInt();
        int count = meta.getInt();
        int size = meta.getInt();
        int magic = meta.getInt();

        if (magic != MAGIC) {
            throw new InvalidBinaryReferencesIndexException("Invalid magic number");
        }
        if (count < 0) {
            throw new InvalidBinaryReferencesIndexException("Invalid count");
        }
        if (size < count * 22 + 16) {
            throw new InvalidBinaryReferencesIndexException("Invalid size");
        }

        return reader.readAtEnd(size, size);
    }

    public static BinaryReferencesIndex parseBinaryReferencesIndex(Buffer buffer) throws InvalidBinaryReferencesIndexException {
        Buffer data = buffer.slice();
        data.limit(data.limit() - FOOTER_SIZE);

        buffer.position(buffer.limit() - FOOTER_SIZE);
        Buffer meta = buffer.slice();

        int crc32 = meta.getInt();
        int count = meta.getInt();
        int size = meta.getInt();
        int magic = meta.getInt();

        if (magic != MAGIC) {
            throw new InvalidBinaryReferencesIndexException("Invalid magic number");
        }
        if (count < 0) {
            throw new InvalidBinaryReferencesIndexException("Invalid count");
        }
        if (size < count * 22 + 16) {
            throw new InvalidBinaryReferencesIndexException("Invalid size");
        }

        CRC32 checksum = new CRC32();
        data.mark();
        data.update(checksum);
        data.reset();

        if ((int) (checksum.getValue()) != crc32) {
            throw new InvalidBinaryReferencesIndexException("Invalid checksum");
        }

        return new BinaryReferencesIndex(parseBinaryReferencesIndex(count, data));
    }

    private static Map<Generation, Map<UUID, Set<String>>> parseBinaryReferencesIndex(int count, Buffer buffer) {
        Map<Generation, Map<UUID, Set<String>>> result = new HashMap<>(count);
        for (int i = 0; i < count; i++) {
            Generation k = parseGeneration(buffer);
            Map<UUID, Set<String>> v = parseEntriesBySegment(buffer);
            result.put(k, v);
        }
        return result;
    }

    private static Generation parseGeneration(Buffer buffer) {
        int generation = buffer.getInt();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2.java [37:105]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    static final int FOOTER_SIZE = 16;

    static Buffer loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException {
        Buffer meta = reader.readAtEnd(FOOTER_SIZE, FOOTER_SIZE);

        int crc32 = meta.getInt();
        int count = meta.getInt();
        int size = meta.getInt();
        int magic = meta.getInt();

        if (magic != MAGIC) {
            throw new InvalidBinaryReferencesIndexException("Invalid magic number");
        }
        if (count < 0) {
            throw new InvalidBinaryReferencesIndexException("Invalid count");
        }
        if (size < count * 22 + 16) {
            throw new InvalidBinaryReferencesIndexException("Invalid size");
        }

        return reader.readAtEnd(size, size);
    }

    public static BinaryReferencesIndex parseBinaryReferencesIndex(Buffer buffer) throws InvalidBinaryReferencesIndexException {
        Buffer data = buffer.slice();
        data.limit(data.limit() - FOOTER_SIZE);

        buffer.position(buffer.limit() - FOOTER_SIZE);
        Buffer meta = buffer.slice();

        int crc32 = meta.getInt();
        int count = meta.getInt();
        int size = meta.getInt();
        int magic = meta.getInt();

        if (magic != MAGIC) {
            throw new InvalidBinaryReferencesIndexException("Invalid magic number");
        }
        if (count < 0) {
            throw new InvalidBinaryReferencesIndexException("Invalid count");
        }
        if (size < count * 22 + 16) {
            throw new InvalidBinaryReferencesIndexException("Invalid size");
        }

        CRC32 checksum = new CRC32();
        data.mark();
        data.update(checksum);
        data.reset();

        if ((int) (checksum.getValue()) != crc32) {
            throw new InvalidBinaryReferencesIndexException("Invalid checksum");
        }

        return new BinaryReferencesIndex(parseBinaryReferencesIndex(count, data));
    }

    private static Map<Generation, Map<UUID, Set<String>>> parseBinaryReferencesIndex(int count, Buffer buffer) {
        Map<Generation, Map<UUID, Set<String>>> result = new HashMap<>(count);
        for (int i = 0; i < count; i++) {
            Generation k = parseGeneration(buffer);
            Map<UUID, Set<String>> v = parseEntriesBySegment(buffer);
            result.put(k, v);
        }
        return result;
    }

    private static Generation parseGeneration(Buffer buffer) {
        int generation = buffer.getInt();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



