Search in sources :

Example 1 with ICsvMapWriter

use of org.supercsv.io.ICsvMapWriter in project photon-model by vmware.

the class TestUtils method writeCsvToFile.

/**
 * Write the updated data back to the CSV
 */
private static void writeCsvToFile(List<Map<String, Object>> rows, Path csvBillZipFilePath) throws Exception {
    String unzippedCsvFilePathStr = csvBillZipFilePath.toString().substring(0, csvBillZipFilePath.toString().lastIndexOf('.'));
    ICsvMapWriter listWriter = null;
    try {
        listWriter = new CsvMapWriter(new FileWriter(unzippedCsvFilePathStr), CsvPreference.STANDARD_PREFERENCE);
        // the header elements are used to map the bean values to each column (names must match)
        final String[] header = new String[] { "InvoiceID", "PayerAccountId", "LinkedAccountId", "RecordType", "RecordId", "ProductName", "RateId", "SubscriptionId", "PricingPlanId", "UsageType", "Operation", "AvailabilityZone", "ReservedInstance", "ItemDescription", "UsageStartDate", "UsageEndDate", "UsageQuantity", "BlendedRate", "BlendedCost", "UnBlendedRate", "UnBlendedCost", "ResourceId", "user:Description", "user:Geo", "user:Name", "user:testTag", "user:testTag2" };
        listWriter.writeHeader(header);
        for (Map<String, Object> row : rows) {
            listWriter.write(row, header);
        }
    } finally {
        if (listWriter != null) {
            listWriter.close();
        }
    }
}
Also used : ICsvMapWriter(org.supercsv.io.ICsvMapWriter) FileWriter(java.io.FileWriter) CsvMapWriter(org.supercsv.io.CsvMapWriter) ICsvMapWriter(org.supercsv.io.ICsvMapWriter)

Example 2 with ICsvMapWriter

use of org.supercsv.io.ICsvMapWriter in project jprime by bgjug.

the class CSVService method exportSubmissions.

public File exportSubmissions(List<Submission> submissions) throws IOException {
    File submissionsCSVFile = File.createTempFile("submissions.", ".csv");
    logger.info("Created submissions file with path: " + submissionsCSVFile.getAbsolutePath());
    try (ICsvMapWriter mapWriter = new CsvMapWriter(new FileWriter(submissionsCSVFile.getAbsolutePath()), CsvPreference.STANDARD_PREFERENCE)) {
        writeSubmissions(submissions, mapWriter);
    }
    return submissionsCSVFile;
}
Also used : ICsvMapWriter(org.supercsv.io.ICsvMapWriter) FileWriter(java.io.FileWriter) CsvMapWriter(org.supercsv.io.CsvMapWriter) ICsvMapWriter(org.supercsv.io.ICsvMapWriter) File(java.io.File)

Example 3 with ICsvMapWriter

use of org.supercsv.io.ICsvMapWriter in project webofneeds by researchstudio-sat.

the class SimonCsvStatisticsRecorder method recordMonitoringStatistics.

@Override
public void recordMonitoringStatistics() {
    ICsvMapWriter mapWriter = null;
    try {
        mapWriter = new CsvMapWriter(new FileWriter(createOutFileObject()), CsvPreference.STANDARD_PREFERENCE);
        final CellProcessor[] processors = getProcessors();
        // write the header
        mapWriter.writeHeader(header);
        // create a simon visitor that writes each line
        SimonVisitor visitor = new CsvSimonVisitor(mapWriter);
        // write the customer maps
        SimonVisitors.visitTree(SimonManager.getRootSimon(), visitor);
    } catch (IOException e) {
        logger.warn("could not write simon statistics", e);
    } finally {
        if (mapWriter != null) {
            try {
                mapWriter.close();
            } catch (IOException e) {
                logger.warn("could not close writer", e);
            }
        }
    }
}
Also used : ICsvMapWriter(org.supercsv.io.ICsvMapWriter) FileWriter(java.io.FileWriter) CellProcessor(org.supercsv.cellprocessor.ift.CellProcessor) CsvMapWriter(org.supercsv.io.CsvMapWriter) ICsvMapWriter(org.supercsv.io.ICsvMapWriter) IOException(java.io.IOException)

Aggregations

FileWriter (java.io.FileWriter)3 CsvMapWriter (org.supercsv.io.CsvMapWriter)3 ICsvMapWriter (org.supercsv.io.ICsvMapWriter)3 File (java.io.File)1 IOException (java.io.IOException)1 CellProcessor (org.supercsv.cellprocessor.ift.CellProcessor)1