From a391e1934ed6228dd1fb425a624f5ed38db6b738 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Mon, 1 Jul 2024 16:01:33 +0200 Subject: [PATCH] Simplify `RecordingStream` bulk read The forced loop-reading was inherited from JMC, but we don't know its purpose. The simpler one-shot impl passes our tests and the output JFR opens in IntelliJ. PS. remove unncessary ByteArray clone. --- .../testutils/parser/RecordingStream.java | 18 +++++++----------- .../jfr/converter/CheckpointEvent.java | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/testutils/parser/RecordingStream.java b/src/main/java/org/openjdk/jmc/flightrecorder/testutils/parser/RecordingStream.java index cead236..5ff0e80 100644 --- a/src/main/java/org/openjdk/jmc/flightrecorder/testutils/parser/RecordingStream.java +++ b/src/main/java/org/openjdk/jmc/flightrecorder/testutils/parser/RecordingStream.java @@ -64,17 +64,13 @@ byte[] stopRecordingWrites() { } public void read(byte[] buffer, int offset, int length) throws IOException { - while (length > 0) { - int read = delegate.read(buffer, offset, length); - if (read == -1) { - throw new IOException("Unexpected EOF"); - } - if (isRecordingWrites) { - toBytesStream.write(buffer, offset, read); - } - offset += read; - length -= read; - position += read; + int read = delegate.read(buffer, offset, length); + if (read == -1) { + throw new IOException("Unexpected EOF"); + } + position += read; + if (isRecordingWrites) { + toBytesStream.write(buffer, offset, read); } } diff --git a/src/main/java/tools/profiler/jfr/converter/CheckpointEvent.java b/src/main/java/tools/profiler/jfr/converter/CheckpointEvent.java index 591d9fd..5abab2d 100644 --- a/src/main/java/tools/profiler/jfr/converter/CheckpointEvent.java +++ b/src/main/java/tools/profiler/jfr/converter/CheckpointEvent.java @@ -46,7 +46,7 @@ public CheckpointEvent(byte[] eventPayload, long eventType, MetadataEvent metada if (eventType != 1) { throw new IOException("Unexpected event type: " + eventType + " (should be 1)"); } - this.payload = ByteBuffer.wrap(eventPayload.clone()); + this.payload = ByteBuffer.wrap(eventPayload); this.stream = new RecordingStream(new ByteArrayInputStream(eventPayload)); this.metadata = metadata; this.listener = listener;