test_class.file: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexWriterTest.java
test_class.identifier: IndexWriterTest
test_case.body: @Test
      public void testWrite() throws Exception {
          IndexWriter writer = newIndexWriter(1);
          writer.addEntry(7, 8, 9, 10, 11, 12, true);
          writer.addEntry(1, 2, 3, 4, 5, 6, false);
          ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE);
          buffer.duplicate()
                  .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5).putInt(6).put((byte) 0)
                  .putLong(7).putLong(8).putInt(9).putInt(10).putInt(11).putInt(12).put((byte) 1)
                  .putInt(0xE2138EB4)
                  .putInt(2)
                  .putInt(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE)
                  .putInt(IndexLoaderV2.MAGIC);
          assertArrayEquals(buffer.array(), writer.write());
      }
test_case.class_method_signature: IndexWriterTest.testWrite()
test_case.full_signature: @Test public void testWrite()
test_case.identifier: testWrite
test_case.invocations: newIndexWriter addEntry addEntry allocate putInt putInt putInt putInt put putInt putInt putInt putInt putLong putLong put putInt putInt putInt putInt putLong putLong duplicate assertArrayEquals array write
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testWrite()
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.declarator: entries = new ArrayList<>()
focal_class.modifier: private final
focal_class.original_string: private final List<Entry> entries = new ArrayList<>();
focal_class.type: List<Entry>
focal_class.var_name: entries
focal_class.file: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexWriter.java
focal_class.identifier: IndexWriter
focal_class.class_method_signature: IndexWriter.newIndexWriter(int blockSize)
focal_class.full_signature: public static IndexWriter newIndexWriter(int blockSize)
focal_class.identifier: newIndexWriter
focal_class.modifiers: public static
focal_class.parameters: (int blockSize)
focal_class.return: IndexWriter
focal_class.signature: IndexWriter newIndexWriter(int blockSize)
focal_class.class_method_signature: IndexWriter.IndexWriter(int blockSize)
focal_class.full_signature: private  IndexWriter(int blockSize)
focal_class.identifier: IndexWriter
focal_class.modifiers: private
focal_class.parameters: (int blockSize)
focal_class.signature:  IndexWriter(int blockSize)
focal_class.class_method_signature: IndexWriter.addEntry(long msb, long lsb, int offset, int size, int generation, int fullGeneration, boolean isCompacted)
focal_class.full_signature: public void addEntry(long msb, long lsb, int offset, int size, int generation, int fullGeneration, boolean isCompacted)
focal_class.identifier: addEntry
focal_class.modifiers: public
focal_class.parameters: (long msb, long lsb, int offset, int size, int generation, int fullGeneration, boolean isCompacted)
focal_class.return: void
focal_class.signature: void addEntry(long msb, long lsb, int offset, int size, int generation, int fullGeneration, boolean isCompacted)
focal_class.class_method_signature: IndexWriter.write()
focal_class.full_signature: public byte[] write()
focal_class.identifier: write
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: byte[]
focal_class.signature: byte[] write()
focal_method.body: public byte[] write() {
          int dataSize = entries.size() * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE;
          int totalSize = ((dataSize + blockSize - 1) / blockSize) * blockSize;
  
          Buffer buffer = Buffer.allocate(totalSize);
          buffer.position(totalSize - dataSize);
  
          entries.sort((a, b) -> {
              if (a.msb < b.msb) {
                  return -1;
              }
              if (a.msb > b.msb) {
                  return 1;
              }
              if (a.lsb < b.lsb) {
                  return -1;
              }
              if (a.lsb > b.lsb) {
                  return 1;
              }
              return 0;
          });
  
          for (Entry entry : entries) {
              buffer.putLong(entry.msb);
              buffer.putLong(entry.lsb);
              buffer.putInt(entry.offset);
              buffer.putInt(entry.size);
              buffer.putInt(entry.generation);
              buffer.putInt(entry.fullGeneration);
              buffer.put((byte) (entry.isCompacted ? 1 : 0));
          }
  
          CRC32 checksum = new CRC32();
          checksum.update(buffer.array(), totalSize - dataSize, dataSize - IndexV2.FOOTER_SIZE);
  
          buffer.putInt((int) checksum.getValue());
          buffer.putInt(entries.size());
          buffer.putInt(totalSize);
          buffer.putInt(IndexLoaderV2.MAGIC);
  
          return buffer.array();
      }
focal_method.class_method_signature: IndexWriter.write()
focal_method.full_signature: public byte[] write()
focal_method.identifier: write
focal_method.invocations: size allocate position sort putLong putLong putInt putInt putInt putInt put update array putInt getValue putInt size putInt putInt array
focal_method.modifiers: public
focal_method.parameters: ()
focal_method.return: byte[]
focal_method.signature: byte[] write()