test_class.file: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV2Test.java
test_class.identifier: IndexLoaderV2Test
test_case.body: @Test
      public void testLoadIndex() throws Exception {
          Buffer entries = Buffer.allocate(2 * IndexEntryV2.SIZE);
          entries.duplicate()
              .putLong(0).putLong(0).putInt(0).putInt(1).putInt(0).putInt(0).put((byte) 0)
              .putLong(0).putLong(1).putInt(1).putInt(1).putInt(0).putInt(0).put((byte) 0);
  
          Buffer buffer = Buffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE);
          buffer.duplicate()
              .put(entries.duplicate())
              .putInt(checksum(entries))
              .putInt(2)
              .putInt(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE)
              .putInt(IndexLoaderV2.MAGIC);
  
          assertNotNull(loadIndex(buffer));
      }
test_case.class_method_signature: IndexLoaderV2Test.testLoadIndex()
test_case.full_signature: @Test public void testLoadIndex()
test_case.identifier: testLoadIndex
test_case.invocations: allocate put putInt putInt putInt putInt putLong putLong put putInt putInt putInt putInt putLong putLong duplicate allocate putInt putInt putInt putInt put duplicate duplicate checksum assertNotNull loadIndex
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testLoadIndex()
focal_class.declarator: MAGIC = ('\n' << 24) + ('1' << 16) + ('K' << 8) + '\n'
focal_class.modifier: static final
focal_class.original_string: static final int MAGIC = ('\n' << 24) + ('1' << 16) + ('K' << 8) + '\n';
focal_class.type: int
focal_class.var_name: MAGIC
focal_class.declarator: blockSize
focal_class.modifier: private final
focal_class.original_string: private final int blockSize;
focal_class.type: int
focal_class.var_name: blockSize
focal_class.file: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV2.java
focal_class.identifier: IndexLoaderV2
focal_class.class_method_signature: IndexLoaderV2.IndexLoaderV2(int blockSize)
focal_class.full_signature:   IndexLoaderV2(int blockSize)
focal_class.identifier: IndexLoaderV2
focal_class.parameters: (int blockSize)
focal_class.signature:  IndexLoaderV2(int blockSize)
focal_class.class_method_signature: IndexLoaderV2.loadIndex(ReaderAtEnd reader)
focal_class.full_signature:  IndexV2 loadIndex(ReaderAtEnd reader)
focal_class.identifier: loadIndex
focal_class.parameters: (ReaderAtEnd reader)
focal_class.return: IndexV2
focal_class.signature: IndexV2 loadIndex(ReaderAtEnd reader)
focal_method.body: IndexV2 loadIndex(ReaderAtEnd reader) throws InvalidIndexException, IOException {
          Buffer meta = reader.readAtEnd(IndexV2.FOOTER_SIZE, IndexV2.FOOTER_SIZE);
  
          int crc32 = meta.getInt();
          int count = meta.getInt();
          int bytes = meta.getInt();
          int magic = meta.getInt();
  
          if (magic != MAGIC) {
              throw new InvalidIndexException("Magic number mismatch");
          }
          if (count < 1) {
              throw new InvalidIndexException("Invalid entry count");
          }
          if (bytes < count * IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE) {
              throw new InvalidIndexException("Invalid size");
          }
          if (bytes % blockSize != 0) {
              throw new InvalidIndexException("Invalid size alignment");
          }
  
          Buffer entries = reader.readAtEnd(IndexV2.FOOTER_SIZE + count * IndexEntryV2.SIZE, count * IndexEntryV2.SIZE);
  
          CRC32 checksum = new CRC32();
          entries.mark();
          entries.update(checksum);
          entries.reset();
          if (crc32 != (int) checksum.getValue()) {
              throw new InvalidIndexException("Invalid checksum");
          }
  
          long lastMsb = Long.MIN_VALUE;
          long lastLsb = Long.MIN_VALUE;
          byte[] entry = new byte[IndexEntryV2.SIZE];
          entries.mark();
          for (int i = 0; i < count; i++) {
              entries.get(entry);
  
              Buffer buffer = wrap(entry);
              long msb = buffer.getLong();
              long lsb = buffer.getLong();
              int offset = buffer.getInt();
              int size = buffer.getInt();
  
              if (lastMsb > msb || (lastMsb == msb && lastLsb > lsb)) {
                  throw new InvalidIndexException("Incorrect entry ordering");
              }
              if (lastMsb == msb && lastLsb == lsb && i > 0) {
                  throw new InvalidIndexException("Duplicate entry");
              }
              if (offset < 0) {
                  throw new InvalidIndexException("Invalid entry offset");
              }
              if (offset % blockSize != 0) {
                  throw new InvalidIndexException("Invalid entry offset alignment");
              }
              if (size < 1) {
                  throw new InvalidIndexException("Invalid entry size");
              }
  
              lastMsb = msb;
              lastLsb = lsb;
          }
          entries.reset();
  
          return new IndexV2(entries);
      }
focal_method.class_method_signature: IndexLoaderV2.loadIndex(ReaderAtEnd reader)
focal_method.full_signature:  IndexV2 loadIndex(ReaderAtEnd reader)
focal_method.identifier: loadIndex
focal_method.invocations: readAtEnd getInt getInt getInt getInt readAtEnd mark update reset getValue mark get wrap getLong getLong getInt getInt reset
focal_method.parameters: (ReaderAtEnd reader)
focal_method.return: IndexV2
focal_method.signature: IndexV2 loadIndex(ReaderAtEnd reader)