修复输出 csv 文件被锁定的问题
This commit is contained in:
parent
7b42f4c0a5
commit
0c0cdca38c
@ -170,6 +170,9 @@ public class OutputExecutor implements ShapeExecutor, SpiderListener {
|
||||
List<String> records = new ArrayList<>(data.size());
|
||||
String[] headers = data.keySet().toArray(new String[data.size()]);
|
||||
try {
|
||||
if (printer == null) {
|
||||
synchronized (cachePrinter) {
|
||||
printer = cachePrinter.get(key);
|
||||
if (printer == null) {
|
||||
CSVFormat format = CSVFormat.DEFAULT.withHeader(headers);
|
||||
FileOutputStream os = new FileOutputStream(csvName);
|
||||
@ -184,10 +187,12 @@ public class OutputExecutor implements ShapeExecutor, SpiderListener {
|
||||
printer = new CSVPrinter(osw, format);
|
||||
cachePrinter.put(key, printer);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
records.add(data.get(headers[i]).toString());
|
||||
}
|
||||
synchronized (printer) {
|
||||
synchronized (cachePrinter) {
|
||||
printer.printRecord(records);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user