class CsvWriter implements DataWriter<CsvWriteOptions> {

  public void write(Table table, CsvWriteOptions options) {
    CsvWriterSettings settings = createSettings(options);

    com.univocity.parsers.csv.CsvWriter csvWriter = null;
    // Creates a writer with the above settings;
    try {
      csvWriter =
          new com.univocity.parsers.csv.CsvWriter(options.destination().createWriter(), settings);

      if (options.header()) {
        String[] header = new String[table.columnCount()];
        for (int c = 0; c < table.columnCount(); c++) {
          header[c] = table.column(c).name();
        }
        csvWriter.writeHeaders(header);
      }
      for (int r = 0; r < table.rowCount(); r++) {
        String[] entries = new String[table.columnCount()];
        for (int c = 0; c < table.columnCount(); c++) {
          table.get(r, c);
          entries[c] = table.getUnformatted(r, c);
        }
        csvWriter.writeRow(entries);
      }
    } finally {
      if (csvWriter != null) {
        csvWriter.flush();
        csvWriter.close();
      }
    }
  }

}