use of org.spf4j.avro.csv.CsvEncoder in project spf4j by zolyfarkas.
the class MStoreViewJInternalFrame method exportButtonActionPerformed.
// GEN-LAST:event_plotButtonActionPerformed
@SuppressFBWarnings("UP_UNUSED_PARAMETER")
private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_exportButtonActionPerformed
TreePath[] selectionPaths = measurementTree.getSelectionPaths();
Set<Schema> selectedTables = getSelectedTables(selectionPaths);
if (!selectedTables.isEmpty()) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
int returnVal = chooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
for (Schema metric : selectedTables) {
try (AvroCloseableIterable<TimeSeriesRecord> obs = reader.getMeasurementData(metric, Instant.EPOCH, Instant.now())) {
CsvWriter writer = Csv.CSV.writer(Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8));
CsvEncoder encoder = new CsvEncoder(writer, Schema.createArray(metric));
encoder.writeHeader();
GenericDatumWriter dw = new GenericDatumWriter(metric);
for (TimeSeriesRecord o : obs) {
dw.write(o, encoder);
}
encoder.flush();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
}
}
}
Aggregations