chia7712 commented on code in PR #15589: URL: https://github.com/apache/kafka/pull/15589#discussion_r1536789020
########## clients/src/main/java/org/apache/kafka/common/telemetry/internals/ClientTelemetryUtils.java: ########## @@ -203,20 +201,19 @@ public static byte[] compress(byte[] raw, CompressionType compressionType) throw public static ByteBuffer decompress(byte[] metrics, CompressionType compressionType) { ByteBuffer data = ByteBuffer.wrap(metrics); - try (InputStream in = compressionType.wrapForInput(data, RecordBatch.CURRENT_MAGIC_VALUE, BufferSupplier.create()); - ByteArrayOutputStream out = new ByteArrayOutputStream()) { - + try (InputStream in = compressionType.wrapForInput(data, RecordBatch.CURRENT_MAGIC_VALUE, BufferSupplier.create())) { byte[] bytes = new byte[data.capacity() * 2]; int nRead; while ((nRead = in.read(bytes, 0, bytes.length)) != -1) { - out.write(bytes, 0, nRead); + try (ByteBufferOutputStream out = new ByteBufferOutputStream(nRead)) { Review Comment: Could we use single try-catch to release both `in` and `out`? ########## clients/src/main/java/org/apache/kafka/common/telemetry/internals/ClientTelemetryUtils.java: ########## @@ -203,20 +201,19 @@ public static byte[] compress(byte[] raw, CompressionType compressionType) throw public static ByteBuffer decompress(byte[] metrics, CompressionType compressionType) { ByteBuffer data = ByteBuffer.wrap(metrics); - try (InputStream in = compressionType.wrapForInput(data, RecordBatch.CURRENT_MAGIC_VALUE, BufferSupplier.create()); - ByteArrayOutputStream out = new ByteArrayOutputStream()) { - + try (InputStream in = compressionType.wrapForInput(data, RecordBatch.CURRENT_MAGIC_VALUE, BufferSupplier.create())) { byte[] bytes = new byte[data.capacity() * 2]; int nRead; while ((nRead = in.read(bytes, 0, bytes.length)) != -1) { - out.write(bytes, 0, nRead); + try (ByteBufferOutputStream out = new ByteBufferOutputStream(nRead)) { + out.write(bytes, 0, nRead); + return out.buffer(); Review Comment: should we call `flip` before returning it?? -- 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. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org