package com.bayer.edam.migration.attic;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogFileCleaner {

	private static final Logger log = LoggerFactory.getLogger(LogFileCleaner.class);
	private static final String[] files = { "C:\\Temp\\Migration AH\\Entry Export\\migration.log",
			"C:\\Temp\\Migration AH\\Entry Export\\migration.log.1", "C:\\Temp\\Migration AH\\Entry Export\\migration.log.2",
			"C:\\Temp\\Migration AH\\Entry Export\\migration.log.3", "C:\\Temp\\Migration AH\\Entry Export\\migration.log.4" };
	private static final File outputFile = new File("C:\\Temp\\Migration AH\\Entry Export\\migration.csv");

	public LogFileCleaner() {
		try {
			log.info("Write CSV header");
			Charset encoding = Charset.forName("UTF-8");
			FileUtils.writeStringToFile(outputFile, "EntryId|~|EntryIdString|~|MediaType|~|Filesize|~|Json", encoding, true);
			
			for (String filename : files) {
				log.info("Reading file " + filename);
				
				List<String> lines = FileUtils.readLines(new File(filename), "UTF-8");
				for (String line : lines) {
					line = line.substring(90) + "\n";
					FileUtils.writeStringToFile(outputFile, line, encoding, true);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {
		new LogFileCleaner();
	}

}
