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

Code Improvements #331

Merged
merged 1 commit into from
Nov 5, 2023
Merged

Code Improvements #331

merged 1 commit into from
Nov 5, 2023

Conversation

khmarbaise
Copy link
Member

  • using Files.newBufferedWriter(), Files.lines()
  • using reader.lines().forEach()
  • Removed inverse logic.
  • Using StandardCharsets.UTF_8 instead of literal texts.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MDEP-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MDEP-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@asfgit asfgit force-pushed the code-improvements branch 2 times, most recently from 76a8214 to 213d2a4 Compare August 15, 2023 16:18

return sb.toString();
try (Stream<String> lines = Files.lines(outputFile.toPath(), Charset.forName(encoding))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can use the charset StandardCharsets.UTF_8 directly here

Copy link
Member Author

@khmarbaise khmarbaise Aug 31, 2023

Choose a reason for hiding this comment

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

No you can't because the String toString(Object o, String nullDefault) is using the String nullDefault... that's the reason. And furthermore it should be configurable via the outputEncoding parameter...

String encoding = Objects.toString(outputEncoding, "UTF-8");

try (Writer w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out), encoding))) {
String encoding = Objects.toString(outputEncoding, StandardCharsets.UTF_8.name());
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for this, you can use the charset object StandardCharsets.UTF_8 instead without converting to a string

Copy link
Member Author

Choose a reason for hiding this comment

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

No you can't because the String toString(Object o, String nullDefault) is using the String nullDefault... that's the reason.


while ((line = reader.readLine()) != null) {
log.info(line);
try (BufferedReader reader = new BufferedReader(new StringReader(string))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The BufferedReader probably doesn't help on a string reader.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately if I would use StringReader only I don't have things like reader.lines()... and the old code used BufferedReader as well...

 * using Files.newBufferedWriter(), Files.lines()
 * using reader.lines().forEach()
 * Removed inverse logic.
 * Using StandardCharsets.UTF_8 instead of literal
   texts.
@asfgit asfgit merged commit f1b2915 into master Nov 5, 2023
36 checks passed
@asfgit asfgit deleted the code-improvements branch November 5, 2023 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants