diff --git a/src/main/java/edu/kit/ifv/mobitopp/actitopp/CSVExportLogger.java b/src/main/java/edu/kit/ifv/mobitopp/actitopp/CSVExportLogger.java index 3739556..340926f 100644 --- a/src/main/java/edu/kit/ifv/mobitopp/actitopp/CSVExportLogger.java +++ b/src/main/java/edu/kit/ifv/mobitopp/actitopp/CSVExportLogger.java @@ -8,6 +8,7 @@ public class CSVExportLogger { + File basepath; FileWriter activitywriter; FileWriter tripwriter; @@ -22,21 +23,21 @@ public class CSVExportLogger */ public CSVExportLogger(File basepath) throws IOException { - activitywriter = new FileWriter(new File(basepath, "actitopp_activities.csv")); - tripwriter = new FileWriter(new File(basepath, "actitopp_trips.csv")); - personwriter = new FileWriter(new File(basepath, "actitopp_persons.csv")); + this.basepath = basepath; + openLogging(false); writeActivityData_header(); writeTripData_header(); writePersonData_header(); + + closeLogging(); } - public void writeLogging(HashMap maptoexport) throws IOException { + openLogging(true); for(Object referenceobject : maptoexport.values()) - { - + { // Householdmap if (referenceobject instanceof ActiToppHousehold) { @@ -45,8 +46,7 @@ public void writeLogging(HashMap maptoexport) throws IOException { exportsinglePerson(actperson); } - } - + } // Personmap if (referenceobject instanceof ActitoppPerson) { @@ -54,9 +54,18 @@ public void writeLogging(HashMap maptoexport) throws IOException exportsinglePerson(actperson); } } + closeLogging(); + } + + + private void openLogging(boolean appendToExistingFile) throws IOException + { + activitywriter = new FileWriter(new File(basepath, "actitopp_activities.csv"), appendToExistingFile); + tripwriter = new FileWriter(new File(basepath, "actitopp_trips.csv"), appendToExistingFile); + personwriter = new FileWriter(new File(basepath, "actitopp_persons.csv"), appendToExistingFile); } - public void closeLogging() throws IOException + private void closeLogging() throws IOException { activitywriter.close(); tripwriter.close(); diff --git a/src/main/java/edu/kit/ifv/mobitopp/actitopp/demo/ExampleActiTopp.java b/src/main/java/edu/kit/ifv/mobitopp/actitopp/demo/ExampleActiTopp.java index f92b2c1..c930d93 100644 --- a/src/main/java/edu/kit/ifv/mobitopp/actitopp/demo/ExampleActiTopp.java +++ b/src/main/java/edu/kit/ifv/mobitopp/actitopp/demo/ExampleActiTopp.java @@ -338,7 +338,6 @@ public static void createAndModelMultiplePersons_Example2() // Output information as csv files CSVExportLogger logger = new CSVExportLogger(new File ("D:")); logger.writeLogging(householdmap); - logger.closeLogging(); } catch (IOException e) {