mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
unify name of CsvOutptPlugin impl
This commit is contained in:
parent
668f9f35ea
commit
9d96131bbf
@ -1,4 +0,0 @@
|
||||
package io.nosqlbench.engine.extensions.csvoutput;
|
||||
|
||||
public class CsvOutput {
|
||||
}
|
@ -2,7 +2,7 @@ package io.nosqlbench.engine.extensions.csvoutput;
|
||||
|
||||
public class CsvOutputPluginInstance {
|
||||
|
||||
public CsvOutput open(String filename, String... headers) {
|
||||
return new CsvOutputWriter(filename, headers);
|
||||
public CsvOutputPluginWriter open(String filename, String... headers) {
|
||||
return new CsvOutputPluginWriter(filename, headers);
|
||||
}
|
||||
}
|
||||
|
@ -8,21 +8,26 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.PosixFilePermissions;
|
||||
import java.util.*;
|
||||
|
||||
public class CsvOutputWriter extends CsvOutput {
|
||||
public class CsvOutputPluginWriter extends CsvOutput {
|
||||
|
||||
private final CSVPrinter printer;
|
||||
private final FileWriter filewriter;
|
||||
private final LinkedHashSet<String> headerKeys;
|
||||
private final String filename;
|
||||
|
||||
public CsvOutputWriter(String filename, String... headers) {
|
||||
public CsvOutputPluginWriter(String filename, String... headers) {
|
||||
try {
|
||||
this.filename = filename;
|
||||
Path filepath = Path.of(filename);
|
||||
Files.createDirectories(filepath.getParent(), PosixFilePermissions.asFileAttribute(
|
||||
PosixFilePermissions.fromString("rwxr-x---")
|
||||
));
|
||||
CSVFormat fmt = CSVFormat.DEFAULT;
|
||||
this.headerKeys = new LinkedHashSet<>(Arrays.asList(headers));
|
||||
try {
|
||||
this.filewriter = new FileWriter(filename);
|
||||
this.filewriter = new FileWriter(filepath.toString());
|
||||
this.printer = new CSVPrinter(filewriter, fmt);
|
||||
if (Files.size(Path.of(filename)) == 0) {
|
||||
printer.printRecord(headerKeys);
|
||||
@ -33,7 +38,7 @@ public class CsvOutputWriter extends CsvOutput {
|
||||
}
|
||||
}
|
||||
|
||||
public CsvOutputWriter write(Value value) {
|
||||
public CsvOutputPluginWriter write(Value value) {
|
||||
List<String> lineout = new ArrayList<>();
|
||||
Map<String, String> provided = new HashMap<>();
|
||||
if (value.isHostObject()) {
|
@ -7,14 +7,14 @@ import org.junit.jupiter.api.Test;
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public class CsvOutputWriterTest {
|
||||
public class CsvOutputPluginWriterTest {
|
||||
|
||||
@Test
|
||||
public void testCsvOutputWriter() {
|
||||
File tmpfile = Files.newTemporaryFile();
|
||||
tmpfile.deleteOnExit();
|
||||
System.out.println("tmpfile="+ tmpfile.getPath());
|
||||
CsvOutputWriter out = new CsvOutputWriter(tmpfile.getPath(), "one", "two");
|
||||
CsvOutputPluginWriter out = new CsvOutputPluginWriter(tmpfile.getPath(), "one", "two");
|
||||
out.write(Value.asValue(Map.of("one","one_","two","two_")));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user