private void dumpHouseholds() { try { new HouseholdsWriterV10(households).writeFile(controlerIO.getOutputFilename(Controler.OUTPUT_PREFIX + Controler.FILENAME_HOUSEHOLDS)); } catch ( Exception ee ) { log.error("Exception writing households.", ee); } }
/*package*/ void writeEndAndCloseFile(){ this.writeEndTag(HouseholdsSchemaV10Names.HOUSEHOLDS); this.close(); }
private void writeMembers(List<Id<Person>> memberIds) throws UncheckedIOException { this.writeStartTag(HouseholdsSchemaV10Names.MEMBERS, null); for (Id<Person> id : memberIds){ atts.clear(); atts.add(createTuple(HouseholdsSchemaV10Names.REFID, id.toString())); this.writeStartTag(HouseholdsSchemaV10Names.PERSONID, atts, true); } this.writeEndTag(HouseholdsSchemaV10Names.MEMBERS); }
/*package*/ void openFileAndWritePreamble(String filename){ this.openFile(filename); this.writeXmlHead(); this.writeHeader(); }
/*package*/ void writeHousehold(Household h) throws UncheckedIOException { this.atts.clear(); atts.add(createTuple(HouseholdsSchemaV10Names.ID, h.getId().toString())); this.writeStartTag(HouseholdsSchemaV10Names.HOUSEHOLD, atts); if ((h.getMemberIds() != null) && !h.getMemberIds().isEmpty()){ this.writeMembers(h.getMemberIds()); } if ((h.getVehicleIds() != null) && !h.getVehicleIds().isEmpty()) { this.writeStartTag(HouseholdsSchemaV10Names.VEHICLES, null); for (Id<Vehicle> id : h.getVehicleIds()){ atts.clear(); atts.add(createTuple(HouseholdsSchemaV10Names.REFID, id.toString())); this.writeStartTag(HouseholdsSchemaV10Names.VEHICLEDEFINITIONID, atts, true); } this.writeEndTag(HouseholdsSchemaV10Names.VEHICLES); } if (h.getIncome() != null){ this.writeIncome(h.getIncome()); } AttributesXmlWriterDelegate attributesWriter = new AttributesXmlWriterDelegate(); attributesWriter.putAttributeConverters(this.attributeConverters); try { this.writer.write(NL); } catch (IOException e) { e.printStackTrace(); } attributesWriter.writeAttributes( "\t\t" , this.writer , h.getAttributes() ); this.writeEndTag(HouseholdsSchemaV10Names.HOUSEHOLD); }
private void writeIncome(Income income) throws UncheckedIOException { atts.clear(); if (income.getCurrency() != null) { atts.add(createTuple(HouseholdsSchemaV10Names.CURRENCY,income.getCurrency())); } atts.add(createTuple(HouseholdsSchemaV10Names.PERIOD, income.getIncomePeriod().toString())); this.writeStartTag(HouseholdsSchemaV10Names.INCOME, atts); this.writeContent(Double.toString(income.getIncome()), true); this.writeEndTag(HouseholdsSchemaV10Names.INCOME); }
public void readFileRunAlgorithmsAndWriteFile(String inputFile, String outputFile){ if (inputFile.equalsIgnoreCase(outputFile)){ throw new IllegalArgumentException("Inputfile and outputfile must not refer to the same filename!"); } hhWriter = new HouseholdsWriterV10(super.getHouseholds()); hhWriter.openFileAndWritePreamble(outputFile); super.readFile(inputFile); counter.printCounter(); hhWriter.writeEndAndCloseFile(); log.info("Done reading households, running algorithms, and writing file"); }
public void writeFile(String filename) throws UncheckedIOException { log.info( Gbl.aboutToWrite( " households", filename ) ) ; this.openFileAndWritePreamble(filename); this.writeHouseholds(this.households); this.writeEndAndCloseFile(); }
private void writeHeader(){ atts.clear(); atts.add(createTuple(XMLNS, MatsimXmlWriter.MATSIM_NAMESPACE)); atts.add(createTuple(XMLNS + ":xsi", DEFAULTSCHEMANAMESPACELOCATION)); atts.add(createTuple("xsi:schemaLocation", MATSIM_NAMESPACE + " " + DEFAULT_DTD_LOCATION + "households_v1.0.xsd")); this.writeStartTag(HouseholdsSchemaV10Names.HOUSEHOLDS, atts); }
public void testBasicReaderWriter() throws IOException { Households households = new HouseholdsImpl(); HouseholdsReaderV10 reader = new HouseholdsReaderV10(households); reader.readFile(this.getPackageInputDirectory() + TESTHOUSEHOLDSINPUT); checkContent(households); HouseholdsWriterV10 writer = new HouseholdsWriterV10(households); String outfilename = this.getOutputDirectory() + TESTXMLOUTPUT; writer.writeFile(outfilename); File outFile = new File(outfilename); assertTrue(outFile.exists()); //read it again to check if the same is read as at the very first beginning of test households = new HouseholdsImpl(); reader = new HouseholdsReaderV10(households); reader.readFile(outfilename); checkContent(households); }