Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ public byte[] compress(byte[] payloadByteArr) throws RpcException {
}

ByteArrayOutputStream out = new ByteArrayOutputStream();
BZip2CompressorOutputStream cos;
try {
cos = new BZip2CompressorOutputStream(out);
try (BZip2CompressorOutputStream cos = new BZip2CompressorOutputStream(out)) {
Copy link
Member

@mytang0 mytang0 May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Out' should also be fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a FilterOutputStream, the underlying output stream should be closed together with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commons-io ByteArrayOutputStream directly operates on memory, not network IO, and does not manipulate file handles, it's close() method is also an empty implementation, and it is not necessary to close。Just like a regular Java object.
org.apache.commons.io.output.ByteArrayOutputStream#close:

 public void close() throws IOException {
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think we needn't do any change.

cos.write(payloadByteArr);
cos.close();
} catch (Exception e) {
throw new IllegalStateException(e);
}
Expand Down
Loading