-
Notifications
You must be signed in to change notification settings - Fork 164
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
fix: Use IOUtils toStream and toString #10975
Conversation
Use IOUtils toString and toInputStream to not change any characters in the file content. fixes #10893
7982bc6
to
b8fa115
Compare
@@ -650,8 +651,8 @@ private static InputStream getStatsFromClassPath(VaadinService service) { | |||
Stats statistics = service.getContext().getAttribute(Stats.class); | |||
|
|||
if (statistics != null) { | |||
return new ByteArrayInputStream( | |||
statistics.statsJson.getBytes(StandardCharsets.UTF_8)); | |||
return IOUtils.toInputStream(statistics.statsJson, |
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.
This the implementation which IOUtils.toInputStream
delegates to
public static InputStream toInputStream(final String input, final Charset encoding) {
return new ByteArrayInputStream(input.getBytes(Charsets.toCharset(encoding)));
}
It's almost identical.
So this should not fix anything even though it may be considered as a small code improvement .
I guess the reason of changing chars is using UTF-8 as encoding while the json statistics is not in UTF-8 for some reason.
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.
This is just to keep the usage similar and more readable.
The main fix to the issue is to not use streamToString(stream)
but IOUtils.toString(stream, StandardCharsets.UTF_8)
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.
OK.
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.
But are you sure this fixes anything ?
No way to make a unit test?
@@ -650,8 +651,8 @@ private static InputStream getStatsFromClassPath(VaadinService service) { | |||
Stats statistics = service.getContext().getAttribute(Stats.class); | |||
|
|||
if (statistics != null) { | |||
return new ByteArrayInputStream( | |||
statistics.statsJson.getBytes(StandardCharsets.UTF_8)); | |||
return IOUtils.toInputStream(statistics.statsJson, |
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.
OK.
Added test. |
SonarQube analysis reported 4 issues
|
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.
Does the test throw without the change?
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.
OK, I see it fails
* fix: Use IOUtils toStream and toString Use IOUtils toString and toInputStream to not change any characters in the file content. fixes #10893
* fix: Use IOUtils toStream and toString Use IOUtils toString and toInputStream to not change any characters in the file content. fixes #10893
* fix: Use IOUtils toStream and toString Use IOUtils toString and toInputStream to not change any characters in the file content. fixes #10893
This ticket/PR has been released with platform 21.0.0.alpha2. For prerelease versions, it will be included in its final version. |
Use IOUtils toString and toInputStream
to not change any characters in the file content.
Using streamToString adds new lines for each usage,
but this can not be done for a json file that contains
in the string content new lines.
fixes #10893