Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #3010]Method manually handles closing an auto-closeable resource [RegistryHandler] #3891

Closed
wants to merge 12 commits into from

Conversation

PickBas
Copy link
Contributor

@PickBas PickBas commented May 9, 2023

Fixes #3010.

Modifications

Used try-with-resources for OutputStream

Documentation

  • Does this pull request introduce a new feature? (no)

Comment on lines 96 to 104
httpExchange.sendResponseHeaders(
200,
Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET).length
);
try (OutputStream out = httpExchange.getResponseBody()) {
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
} catch (IOException ioe) {
log.warn("out close failed...", e);
}
Copy link
Member

Choose a reason for hiding this comment

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

how about like this:

byte[] bytes = Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET);
httpExchange.sendResponseHeaders(
                200,
                bytes.length
            );
            try (OutputStream out = httpExchange.getResponseBody()) {
                out.write(bytes);
            } catch (IOException ioe) {
                log.warn("out close failed...", e);
            }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mxsm Done! Have a look, please

Comment on lines 88 to 91
httpExchange.sendResponseHeaders(
200,
Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET).length
);
Copy link
Member

Choose a reason for hiding this comment

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

It needs to be modified here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mxsm Fixed.

@harshithasudhakar
Copy link
Member

@PickBas Please fix the conflicts

@PickBas PickBas closed this Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Method manually handles closing an auto-closeable resource [MetaHandler]
3 participants