From 2934bb11ea9d4e9580ecbf012e38c9579e415ee7 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 15 May 2018 19:41:40 +0100 Subject: [PATCH 1/2] Close file ready with try-with-resources --- .../kemitix/checkstyle/ruleset/builder/ReadmeWriter.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java index 12d1c41..3cc8ae5 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java @@ -32,6 +32,7 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Writes the README file. @@ -94,8 +95,9 @@ class ReadmeWriter implements CommandLineRunner { } private String readFile(final Path file) throws IOException { - return Files.lines(file, StandardCharsets.UTF_8) - .collect(Collectors.joining(NEWLINE)); + try (Stream lines = Files.lines(file, StandardCharsets.UTF_8)) { + return lines.collect(Collectors.joining(NEWLINE)); + } } } From 604acf25098cec9613613b9d4a0a563367d127e0 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 15 May 2018 19:50:16 +0100 Subject: [PATCH 2/2] Use Files.readAllLines --- .../net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java index 3cc8ae5..63653c4 100644 --- a/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java +++ b/builder/src/main/java/net/kemitix/checkstyle/ruleset/builder/ReadmeWriter.java @@ -32,7 +32,6 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.function.Predicate; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * Writes the README file. @@ -95,9 +94,7 @@ class ReadmeWriter implements CommandLineRunner { } private String readFile(final Path file) throws IOException { - try (Stream lines = Files.lines(file, StandardCharsets.UTF_8)) { - return lines.collect(Collectors.joining(NEWLINE)); - } + return String.join(NEWLINE, Files.readAllLines(file, StandardCharsets.UTF_8)); } }