@@ -174,18 +174,7 @@ public static String trimTrailingWhitespace(Collection<String> lines, String lin
174
174
}
175
175
176
176
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 );
189
178
return trimTrailingWhitespace (lines , lineEnding );
190
179
}
191
180
@@ -199,9 +188,14 @@ public static String replaceLineEndings(Collection<String> lines, String lineEnd
199
188
}
200
189
201
190
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 ) {
202
196
List <String > lines = new ArrayList <>();
203
- {
204
- BufferedReader reader = new BufferedReader ( new StringReader ( text ));
197
+ try ( BufferedReader reader = new BufferedReader ( new StringReader ( text ))) {
198
+
205
199
try {
206
200
for (String line = reader .readLine (); line != null ; line = reader .readLine ()) {
207
201
lines .add (line );
@@ -210,7 +204,9 @@ public static String replaceLineEndings(String text, String lineEnding) {
210
204
} catch (IOException ex ) {
211
205
Exceptions .printStackTrace (ex );
212
206
}
207
+ } catch (IOException ex ) {
208
+ Exceptions .printStackTrace (ex );
213
209
}
214
- return replaceLineEndings ( lines , lineEnding ) ;
210
+ return lines ;
215
211
}
216
212
}
0 commit comments