use of org.apache.commons.csv.CSVPrinter in project opennms by OpenNMS.
the class RScriptExecutor method toCsv.
/**
* Convert the table to a CSV string.
*/
protected static StringBuilder toCsv(final RowSortedTable<Long, String, Double> table) throws IOException {
final String[] columnNames = table.columnKeySet().toArray(new String[] {});
final StringBuilder sb = new StringBuilder();
final CSVPrinter printer = CSVFormat.RFC4180.withHeader(columnNames).print(sb);
for (long rowIndex : table.rowKeySet()) {
for (String columnName : columnNames) {
Double value = table.get(rowIndex, columnName);
if (value == null) {
value = Double.NaN;
}
printer.print(value);
}
printer.println();
}
return sb;
}
use of org.apache.commons.csv.CSVPrinter in project jackrabbit-oak by apache.
the class CSVFileGenerator method generate.
public void generate(FluentIterable<BinaryResource> binaries) throws IOException {
Closer closer = Closer.create();
int count = 0;
try {
CSVPrinter printer = new CSVPrinter(Files.newWriter(outFile, Charsets.UTF_8), CSVFileBinaryResourceProvider.FORMAT);
closer.register(printer);
for (BinaryResource br : binaries) {
count++;
printer.printRecord(br.getBlobId(), br.getByteSource().size(), br.getMimeType(), br.getEncoding(), br.getPath());
}
printer.flush();
log.info("Generated csv output at {} with {} entries", outFile.getAbsolutePath(), count);
} finally {
closer.close();
}
}
Aggregations