}
//Add a BOM for Excel
destination.write(charset.encode("\ufeff").array());
CsvWriter out = new CsvWriter(destination, ',', charset);
String[] row = new String[NUM_OUTPUT_COLUMNS];
row[ID_COLUMN] = ID_COLUMN_NAME;
row[PARTICIPANT_COLUMN] = PARTICIPANT_COLUMN_NAME;
row[TIME_COLUMN] = TIME_COLUMN_NAME;
row[MESSAGE_COLUMN] = MESSAGE_COLUMN_NAME;
row[TRUTH_COLUMN] = TRUTH_COLUMN_NAME;
row[PREDICTION_COLUMN] = PREDICTION_COLUMN_NAME;
row[CONFIDENCE_COLUMN] = CONFIDENCE_COLUMN_NAME;
row[SEGMENT_COLUMN] = SEGMENT_COLUMN_NAME;
out.writeRecord(row);
for (Message message : messages) {
row[ID_COLUMN] = Integer.toString(message.getId());
row[PARTICIPANT_COLUMN] = message.getParticipant();
row[TIME_COLUMN] = dateFormat.format(message.getTimestamp());
row[MESSAGE_COLUMN] = message.getMessage();
row[TRUTH_COLUMN] = message.hasTrueLabel() ? message.getTrueLabel().toString() : null;
row[PREDICTION_COLUMN] = message.hasPredictedLabel() ? message.getPredictedLabel().toString() : null;
row[CONFIDENCE_COLUMN] = message.hasPredictionConfidence() ? message.getPredictionConfidence().toString() : null;
row[SEGMENT_COLUMN] = message.hasSegmentId() ? Integer.toString(message.getSegmentId()) : null;
out.writeRecord(row);
}
out.flush();
return true;
}