Source:
private void writeToChannelVersionTwo(WritableByteChannel channel, FileSmoosher smoosher) throws IOException { if (smoosher == null) { throw new IAE("version 2 GenericIndexedWriter requires FileSmoosher."); } File f = ioPeon.getFile(makeFilename("headerLong")); Preconditions.checkNotNull(f, "header file missing."); int bagSizePower = bagSizePower(); OutputStream metaOut = Channels.newOutputStream(channel); metaOut.write(GenericIndexed.VERSION_TWO); metaOut.write(objectsSorted ? 0x1 : 0x0); metaOut.write(Ints.toByteArray(bagSizePower)); metaOut.write(Ints.toByteArray(Ints.checkedCast(numWritten))); metaOut.write(Ints.toByteArray(fileNameByteArray.length)); metaOut.write(fileNameByteArray); try (RandomAccessFile headerFile = new RandomAccessFile(f, "r")) { long previousValuePosition = 0; int bagSize = 1 << bagSizePower; int numberOfFilesRequired = (int) numWritten / bagSize; if ((numWritten % bagSize) != 0) { numberOfFilesRequired += 1; } try (InputStream is = new FileInputStream(ioPeon.getFile(makeFilename("values")))) { int counter = -1; byte[] buffer = new byte[1 << 16]; for (int i = 0; i < numberOfFilesRequired; i++) { if (i != numberOfFilesRequired - 1) { headerFile.seek((bagSize + counter) * Longs.BYTES); counter = counter + bagSize; } else { headerFile.seek((numWritten - 1) * Longs.BYTES); } long valuePosition = Long.reverseBytes(headerFile.readLong()); long numBytesToPutInFile = valuePosition - previousValuePosition; try (SmooshedWriter smooshChannel = smoosher .addWithSmooshedWriter(generateValueFileName(filenameBase, i), numBytesToPutInFile)) { writeBytesIntoSmooshedChannel(numBytesToPutInFile, buffer, smooshChannel, is); previousValuePosition = valuePosition; } } } writeHeader(smoosher, headerFile, bagSizePower); } }

Target:
private void writeToChannelVersionTwo(WritableByteChannel channel, FileSmoosher smoosher) throws IOException { if (smoosher == null) { throw new IAE("version 2 GenericIndexedWriter requires FileSmoosher."); } int bagSizePower = bagSizePower(); OutputStream metaOut = Channels.newOutputStream(channel); metaOut.write(GenericIndexed.VERSION_TWO); metaOut.write(objectsSorted ? 0x1 : 0x0); metaOut.write(Ints.toByteArray(bagSizePower)); metaOut.write(Ints.toByteArray(Ints.checkedCast(numWritten))); metaOut.write(Ints.toByteArray(fileNameByteArray.length)); metaOut.write(fileNameByteArray); try (RandomAccessFile headerFile = new RandomAccessFile(ioPeon.getFile(makeFilename("headerLong")), "r")) { Preconditions.checkNotNull(headerFile, "header file missing."); long previousValuePosition = 0; int bagSize = 1 << bagSizePower; int numberOfFilesRequired = GenericIndexed.getNumberOfFilesRequired(bagSize, numWritten); byte[] buffer = new byte[1 << 16]; try (InputStream is = new FileInputStream(ioPeon.getFile(makeFilename("values")))) { int counter = -1; for (int i = 0; i < numberOfFilesRequired; i++) { if (i != numberOfFilesRequired - 1) { headerFile.seek((bagSize + counter) * Longs.BYTES); counter = counter + bagSize; } else { headerFile.seek((numWritten - 1) * Longs.BYTES); } long valuePosition = Long.reverseBytes(headerFile.readLong()); long numBytesToPutInFile = valuePosition - previousValuePosition; try (SmooshedWriter smooshChannel = smoosher .addWithSmooshedWriter(generateValueFileName(filenameBase, i), numBytesToPutInFile)) { writeBytesIntoSmooshedChannel(numBytesToPutInFile, buffer, smooshChannel, is); previousValuePosition = valuePosition; } } } writeHeaderLong(smoosher, headerFile, bagSizePower, buffer); } }