All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.leonarduk.bookkeeper.file.CsvFormatter Maven / Gradle / Ivy

There is a newer version: 1.8
Show newest version
/**
 * FreeAgentCSVFormatter
 *
 * @author ${author}
 * @since 28-Jun-2016
 */
package com.leonarduk.bookkeeper.file;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class CsvFormatter implements FileFormatter {

	@Override
	public File format(final List transactionRecords,
	        final String outputFileName) throws IOException {
		final File outputFile = new File(outputFileName);
		final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
		try (PrintWriter writer = new PrintWriter(outputFile, "UTF-8");) {
			for (final TransactionRecord transactionRecord : transactionRecords) {
				final Date date = transactionRecord.getDate();
				writer.println(formatter.format(date) + "," + transactionRecord.getAmount() + ","
				        + transactionRecord.getDescription().replaceAll(",", ";"));
			}
		}
		return outputFile;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy