private static MemoryRecords convertRecords(MemoryRecords recordsToConvert, byte toMagic, int bytesToConvert) throws IOException {
        try (FileRecords inputRecords = FileRecords.open(tempFile())) {
            inputRecords.append(recordsToConvert);
            inputRecords.flush();

            LazyDownConversionRecords lazyRecords = new LazyDownConversionRecords(new TopicPartition("test", 1),
                    inputRecords, toMagic, 0L, Time.SYSTEM);
            LazyDownConversionRecordsSend lazySend = lazyRecords.toSend();
            File outputFile = tempFile();
            ByteBuffer convertedRecordsBuffer;
            try (TransferableChannel channel = toTransferableChannel(FileChannel.open(outputFile.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE))) {
                int written = 0;
                while (written < bytesToConvert) written += lazySend.writeTo(channel, written, bytesToConvert - written);
                try (FileRecords convertedRecords = FileRecords.open(outputFile, true, written, false)) {
                    convertedRecordsBuffer = ByteBuffer.allocate(convertedRecords.sizeInBytes());
                    convertedRecords.readInto(convertedRecordsBuffer, 0);
                }
            }
            return MemoryRecords.readableRecords(convertedRecordsBuffer);
        }
    }
Test the lazy down-conversion path.

If `overflow` is true, the number of bytes we want to convert is much larger
than the number of bytes we get after conversion. This causes overflow message batch(es) to be appended towards the
end of the converted output.
clients/src/test/java/org/apache/kafka/common/record/LazyDownConversionRecordsTest.java