-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBatchConversion.java
64 lines (42 loc) · 1.35 KB
/
BatchConversion.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
55
56
57
58
59
60
61
62
63
64
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import com.google.gson.JsonObject;
public class BatchConversion implements Runnable {
ConcurrentHashMap<Long, String> batch = new ConcurrentHashMap<Long, String>();
FileConfiguration fileConfig;
BatchConversion(HashMap<Long, String> batch, FileConfiguration fileConfig) {
this.batch = new ConcurrentHashMap<>(batch);
this.fileConfig = fileConfig;
}
public void run() {
// System.out.println(Thread.currentThread().getName() + " Start.");
String jsonLines = "";
BufferedWriter buffer = MyFileWriter.getBuffer();
for (ConcurrentHashMap.Entry<Long, String> lineValue : batch.entrySet()) {
JsonObject obj = new JsonObject();
String line = lineValue.getValue();
String[] fields = line.split(",");
if (fields.length != fileConfig.getFieldsCount()) {
System.out.println("Missing Fields");
} else {
for (int j = 0; j < fileConfig.getFieldsCount(); j++) {
obj.addProperty(fileConfig.fields[j], fields[j]);
}
FileValues.fieldValues.add(obj);
jsonLines += obj.toString() + "\n";
}
}
try {
buffer.write(jsonLines);
} catch (IOException e) {
e.printStackTrace();
}
try {
ThreadPool.stopBatchProcess();
} catch (IOException e) {
e.printStackTrace();
}
}
}