Search in sources :

Example 21 with CSVWriter

use of au.com.bytecode.opencsv.CSVWriter in project flowml by beautifulNow1992.

the class CsvTableRenderer method render.

@Override
public void render(Writer w, int indent) {
    TableModel tableModel = textTable.getTableModel();
    try (CSVWriter csvWriter = new CSVWriter(w)) {
        String[] headers = new String[tableModel.getColumnCount()];
        for (int i = 0; i < headers.length; i++) {
            headers[i] = tableModel.getColumnName(i);
        }
        csvWriter.writeNext(headers);
        for (int i = 0; i < tableModel.getRowCount(); i++) {
            String[] line = new String[tableModel.getColumnCount()];
            for (int j = 0; j < tableModel.getColumnCount(); j++) {
                Object valueAt = tableModel.getValueAt(i, j);
                line[j] = String.valueOf(valueAt);
            }
            csvWriter.writeNext(line);
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
Also used : CSVWriter(au.com.bytecode.opencsv.CSVWriter) IOException(java.io.IOException) TableModel(javax.swing.table.TableModel)

Example 22 with CSVWriter

use of au.com.bytecode.opencsv.CSVWriter in project mica2 by obiba.

the class CsvReportGenerator method write.

public void write(OutputStream outputStream) {
    try (CSVWriter writer = new CSVWriter(new PrintWriter(outputStream))) {
        writeHeader(writer);
        writeSummary(writer);
        writeEachDataAccessRequest(writer);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : CSVWriter(au.com.bytecode.opencsv.CSVWriter) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) PrintWriter(java.io.PrintWriter)

Example 23 with CSVWriter

use of au.com.bytecode.opencsv.CSVWriter in project mica2 by obiba.

the class CsvPersonsWriter method write.

public ByteArrayOutputStream write(Mica.PersonsDto persons) throws IOException {
    ByteArrayOutputStream values = new ByteArrayOutputStream();
    CSVWriter writer = null;
    try {
        writer = new CSVWriter(new PrintWriter(values));
        writer.writeNext(headers.toArray(new String[headers.size()]));
        writeBody(writer, persons);
    } finally {
        if (writer != null)
            writer.close();
    }
    return values;
}
Also used : CSVWriter(au.com.bytecode.opencsv.CSVWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter)

Aggregations

CSVWriter (au.com.bytecode.opencsv.CSVWriter)23 IOException (java.io.IOException)9 FileWriter (java.io.FileWriter)7 PrintWriter (java.io.PrintWriter)5 ArrayList (java.util.ArrayList)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 File (java.io.File)3 StringWriter (java.io.StringWriter)2 List (java.util.List)2 Lists (com.google.common.collect.Lists)1 Measure (com.secupwn.aimsicd.data.model.Measure)1 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)1 Tuple (edu.uci.ics.texera.api.tuple.Tuple)1 UncheckedIOException (java.io.UncheckedIOException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors (java.util.stream.Collectors)1 TableModel (javax.swing.table.TableModel)1 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)1 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)1