-
Notifications
You must be signed in to change notification settings - Fork 625
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
Conversation
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); | ||
} |
There was a problem hiding this comment.
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);
}
There was a problem hiding this comment.
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
httpExchange.sendResponseHeaders( | ||
200, | ||
Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET).length | ||
); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mxsm Fixed.
@PickBas Please fix the conflicts |
Fixes #3010.
Modifications
Used try-with-resources for OutputStream
Documentation