-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoSomeStuff.java
54 lines (40 loc) · 1.34 KB
/
DoSomeStuff.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package it.at;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.stream.Stream;
import com.google.common.collect.Lists;
public class DoSomeStuff {
private static final Path R = Paths.get("/home/developer/Desktop/source.log");
private static final Path W = Paths.get("/home/developer/Desktop/destination.log");
public static void main(String[] args) throws Exception {
Files.createFile(W);
final List<String> buffer = Lists.newArrayList();
try (Stream<String> stream = Files.lines(R)) {
stream.forEachOrdered(line -> {
buffer.add(transform(line));
if (buffer.size() > 5000) {
write(buffer);
}
});
}
write(buffer);
}
private static String transform(String line) {
/*
real mapping ...
*/
return line;
}
private static void write(final List<String> buffer) {
try {
Files.write(W, buffer, StandardOpenOption.APPEND);
} catch (IOException e) {
e.printStackTrace();
}
buffer.clear();
}
}