Skip to content
Open
Show file tree
Hide file tree
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 @@ -368,10 +368,9 @@ private String generatePrivatePemKey(KeyPair keyPair) throws IOException {
private String generatePemKey(String type, byte[] content) throws IOException {
PemObject pemObject = new PemObject(type, content);
StringWriter str = new StringWriter();
JcaPEMWriter jcaPEMWriter = new JcaPEMWriter(str);
jcaPEMWriter.writeObject(pemObject);
jcaPEMWriter.close();
str.close();
try (JcaPEMWriter jcaPEMWriter = new JcaPEMWriter(str)) {
jcaPEMWriter.writeObject(pemObject);
}
return str.toString();
Comment on lines 370 to 374
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The StringWriter should be included in the try-with-resources statement to ensure it is properly closed. While StringWriter.close() doesn't throw exceptions or manage external resources, following the pattern consistently ensures best practices.

Copilot uses AI. Check for mistakes.
}

Expand Down
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)) {
cos.write(payloadByteArr);
cos.close();
} catch (Exception e) {
throw new IllegalStateException(e);
}
Expand All @@ -75,9 +72,9 @@ public byte[] decompress(byte[] payloadByteArr) {
}

ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(payloadByteArr);
try {
BZip2CompressorInputStream unZip = new BZip2CompressorInputStream(in);
try (ByteArrayInputStream in = new ByteArrayInputStream(payloadByteArr);
BZip2CompressorInputStream unZip = new BZip2CompressorInputStream(in)) {

byte[] buffer = new byte[2048];
int n;
while ((n = unZip.read(buffer)) >= 0) {
Expand Down
Loading