Source:
<code>public static final GZIIndex loadIndex(final Path indexPath) throws IOException { if (indexPath == null) { throw new IllegalArgumentException("null input path"); } ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.order(ByteOrder.LITTLE_ENDIAN); try (final ByteChannel channel = Files.newByteChannel(indexPath)) { if (Long.BYTES != channel.read(buffer)) { throw getCorruptedIndexException(indexPath, "less than " + Long.BYTES+ "bytes"); } buffer.flip(); final int numberOfEntries; try { numberOfEntries = Math.toIntExact(buffer.getLong()); } catch (ArithmeticException e) { buffer.flip(); throw getCorruptedIndexException(indexPath, String.format("HTSJDK cannot handle more than %d entries in .gzi index, but found %s", Integer.MAX_VALUE, buffer.getLong())); } final List<IndexEntry> entries = new ArrayList<>(numberOfEntries + 1); entries.add(FIRST_MAPPING); buffer = allocateBuffer(numberOfEntries, false); channel.read(buffer); buffer.flip(); for (int i = 1; i <= numberOfEntries; i++) { final IndexEntry entry; try { entry = new IndexEntry(buffer.getLong(), buffer.getLong()); } catch (IllegalArgumentException e) { throw new IOException(String.format("Corrupted index file: %s (%s)", indexPath.toUri(), e.getMessage())); } if (entries.get(i - 1).getCompressedOffset() >= entry.getCompressedOffset() || entries.get(i - 1).getUncompressedOffset() >= entry.getUncompressedOffset()) { throw getCorruptedIndexException(indexPath, String.format("index entries in misplaced order - %s vs %s", entries.get(i - 1), entry)); } <START> <END> entries.add(entry); } return new GZIIndex(entries); } }</code><technical_language>bother flipping buffer here</technical_language>

Target:
public static final GZIIndex loadIndex(final Path indexPath) throws IOException { if (indexPath == null) { throw new IllegalArgumentException("null input path"); } ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.order(ByteOrder.LITTLE_ENDIAN); try (final ByteChannel channel = Files.newByteChannel(indexPath)) { if (Long.BYTES != channel.read(buffer)) { throw getCorruptedIndexException(indexPath, "less than " + Long.BYTES+ "bytes", null); } buffer.flip(); final int numberOfEntries; try { numberOfEntries = Math.toIntExact(buffer.getLong()); } catch (ArithmeticException e) { buffer.flip(); throw getCorruptedIndexException(indexPath, String.format("HTSJDK cannot handle more than %d entries in .gzi index, but found %s", Integer.MAX_VALUE, buffer.getLong()), e); } final List<IndexEntry> entries = new ArrayList<>(numberOfEntries); buffer = allocateBuffer(numberOfEntries, false); channel.read(buffer); buffer.flip(); for (int i = 0; i < numberOfEntries; i++) { final IndexEntry entry; try { entry = new IndexEntry(buffer.getLong(), buffer.getLong()); } catch (IllegalArgumentException e) { throw getCorruptedIndexException(indexPath, e.getMessage(), e); } if (i == 0) { if (entry.getUncompressedOffset() == 0 && entry.getCompressedOffset() == 0) { throw getCorruptedIndexException(indexPath, "first block index entry should not be present", null); } } else if (entries.get(i - 1).getCompressedOffset() >= entry.getCompressedOffset() || entries.get(i - 1).getUncompressedOffset() >= entry.getUncompressedOffset()) { throw getCorruptedIndexException(indexPath, String.format("index entries in misplaced order - %s vs %s", entries.get(i - 1), entry), null); } entries.add(entry); } return new GZIIndex(entries); } }