Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

Commit

Permalink
Support Java 7 #81 - added try with resources
Browse files Browse the repository at this point in the history
  • Loading branch information
markiewb committed Jan 25, 2016
1 parent 7bc8e8f commit f738fee
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,7 @@ public static String trimTrailingWhitespace(Collection<String> lines, String lin
}

public static String trimTrailingWhitespace(String text, String lineEnding) {
List<String> lines = new ArrayList<>();
{
BufferedReader reader = new BufferedReader(new StringReader(text));
try {
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
lines.add(line);
}
reader.close();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
List<String> lines = readLines(text);
return trimTrailingWhitespace(lines, lineEnding);
}

Expand All @@ -199,9 +188,14 @@ public static String replaceLineEndings(Collection<String> lines, String lineEnd
}

public static String replaceLineEndings(String text, String lineEnding) {
List<String> lines = readLines(text);
return replaceLineEndings(lines, lineEnding);
}

public static List<String> readLines(String text) {
List<String> lines = new ArrayList<>();
{
BufferedReader reader = new BufferedReader(new StringReader(text));
try (BufferedReader reader = new BufferedReader(new StringReader(text))) {

try {
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
lines.add(line);
Expand All @@ -210,7 +204,9 @@ public static String replaceLineEndings(String text, String lineEnding) {
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
return replaceLineEndings(lines, lineEnding);
return lines;
}
}

0 comments on commit f738fee

Please sign in to comment.