ijuma commented on a change in pull request #9516: URL: https://github.com/apache/kafka/pull/9516#discussion_r540195130
########## File path: clients/src/test/java/org/apache/kafka/common/record/LazyDownConversionRecordsTest.java ########## @@ -160,20 +161,21 @@ private static MemoryRecords convertRecords(MemoryRecords recordsToConvert, byte inputRecords, toMagic, 0L, Time.SYSTEM); LazyDownConversionRecordsSend lazySend = lazyRecords.toSend(); File outputFile = tempFile(); - FileChannel channel = FileChannel.open(outputFile.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE); - - int written = 0; - while (written < bytesToConvert) - written += lazySend.writeTo(channel, written, bytesToConvert - written); - - FileRecords convertedRecords = FileRecords.open(outputFile, true, (int) channel.size(), false); - ByteBuffer convertedRecordsBuffer = ByteBuffer.allocate(convertedRecords.sizeInBytes()); - convertedRecords.readInto(convertedRecordsBuffer, 0); - - // cleanup - convertedRecords.close(); - channel.close(); - + ByteBuffer convertedRecordsBuffer; + try (FileChannel fileChannel = FileChannel.open(outputFile.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE)) { + ByteBuffer buf; + try (org.apache.kafka.common.requests.ByteBufferChannel channel = + new org.apache.kafka.common.requests.ByteBufferChannel(bytesToConvert)) { Review comment: I don't think you can use this as a general class as it stands. A previous PR changed it to be non general, it seems: ```java @Override public long write(ByteBuffer[] srcs, int offset, int length) { int position = buf.position(); for (int i = 0; i < length; i++) { ByteBuffer src = srcs[i].duplicate(); if (i == 0) { src.position(src.position() + offset); } buf.put(src); } return buf.position() - position; } ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org