Browse Source

Use Streams in TextFile.

pull/23/head
Greg Holmes 9 years ago
parent
commit
fdabe904f0
1 changed files with 2 additions and 6 deletions
  1. 2
    6
      src/com/dmdirc/util/io/TextFile.java

+ 2
- 6
src/com/dmdirc/util/io/TextFile.java View File

29
 import java.nio.charset.Charset;
29
 import java.nio.charset.Charset;
30
 import java.nio.file.Files;
30
 import java.nio.file.Files;
31
 import java.nio.file.Path;
31
 import java.nio.file.Path;
32
-import java.util.ArrayList;
33
 import java.util.Collections;
32
 import java.util.Collections;
34
 import java.util.List;
33
 import java.util.List;
34
+import java.util.stream.Collectors;
35
 
35
 
36
 /**
36
 /**
37
  * Allows reading and writing to a plain text file via a list of lines.
37
  * Allows reading and writing to a plain text file via a list of lines.
157
     public void readLines() throws IOException {
157
     public void readLines() throws IOException {
158
         if (path == null) {
158
         if (path == null) {
159
             try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, charset))) {
159
             try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, charset))) {
160
-                lines = new ArrayList<>();
161
-                String line;
162
-                while ((line = reader.readLine()) != null) {
163
-                    lines.add(line);
164
-                }
160
+                lines = reader.lines().collect(Collectors.toList());
165
             }
161
             }
166
         } else {
162
         } else {
167
             lines = Files.readAllLines(path, charset);
163
             lines = Files.readAllLines(path, charset);

Loading…
Cancel
Save