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

Commit f738fee

Browse files
committed
Support Java 7 #81 - added try with resources
1 parent 7bc8e8f commit f738fee

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/main/java/com/welovecoding/nbeditorconfig/io/reader/FileInfoReader.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,7 @@ public static String trimTrailingWhitespace(Collection<String> lines, String lin
174174
}
175175

176176
public static String trimTrailingWhitespace(String text, String lineEnding) {
177-
List<String> lines = new ArrayList<>();
178-
{
179-
BufferedReader reader = new BufferedReader(new StringReader(text));
180-
try {
181-
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
182-
lines.add(line);
183-
}
184-
reader.close();
185-
} catch (IOException ex) {
186-
Exceptions.printStackTrace(ex);
187-
}
188-
}
177+
List<String> lines = readLines(text);
189178
return trimTrailingWhitespace(lines, lineEnding);
190179
}
191180

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

201190
public static String replaceLineEndings(String text, String lineEnding) {
191+
List<String> lines = readLines(text);
192+
return replaceLineEndings(lines, lineEnding);
193+
}
194+
195+
public static List<String> readLines(String text) {
202196
List<String> lines = new ArrayList<>();
203-
{
204-
BufferedReader reader = new BufferedReader(new StringReader(text));
197+
try (BufferedReader reader = new BufferedReader(new StringReader(text))) {
198+
205199
try {
206200
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
207201
lines.add(line);
@@ -210,7 +204,9 @@ public static String replaceLineEndings(String text, String lineEnding) {
210204
} catch (IOException ex) {
211205
Exceptions.printStackTrace(ex);
212206
}
207+
} catch (IOException ex) {
208+
Exceptions.printStackTrace(ex);
213209
}
214-
return replaceLineEndings(lines, lineEnding);
210+
return lines;
215211
}
216212
}

0 commit comments

Comments
 (0)