Skip to content

Commit

Permalink
Simplify RecordingStream bulk read
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dagguh committed Jul 1, 2024
1 parent c288db9 commit a391e19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a391e19

Please sign in to comment.