List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:jfix.db4o.engine.PersistenceEngineXStream.java
public void close() { try {/*from ww w.ja v a2s. c om*/ XStream xstream = new XStream(new DomDriver()); xstream.setMode(XStream.ID_REFERENCES); FileWriter writer = new FileWriter(filename); xstream.toXML(objects, writer); writer.close(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:edu.kit.dama.transfer.client.types.TransferTask.java
/** * Writes a list of TransferTask entities in XML format into pFile * * @param pTasks The list of tasks to persist * @param pFile The file where the data will be written to * * @throws IOException If the file could not be written */// w ww. ja va 2 s .c om public static void toXML(List<TransferTask> pTasks, File pFile) throws IOException { StringBuilder buffer = new StringBuilder(); FileWriter writer = null; buffer.append("<transferTasks>\n"); try { writer = new FileWriter(pFile); int cnt = 0; for (TransferTask task : pTasks) { buffer.append(task.toXml()).append("\n"); cnt++; if (cnt % 100 == 0) {//flush buffer all 100 tasks writer.write(buffer.toString()); writer.flush(); buffer = new StringBuilder(); } } writer.write(buffer.toString()); writer.write("</transferTasks>\n"); writer.flush(); } finally { if (writer != null) { try { writer.close(); } catch (IOException ioe) { } } } }
From source file:freightKt.KTFreight_v3.java
/** * Prft ob alle Services auch in den geplanten Touren vorkommen, d.h., ob sie auhc tatschslcih geplant wurden. * Falls nicht: log.Error und Ausgabe einer Datei: "#UnassignedServices.txt" mit den Service-Ids. * @param carriers// w ww . j av a 2 s.c o m */ //TODO: Ausgabe der Anassigned Services in Run-Verzeichnis und dafrin der bersicht nur eine Nennung der Anzahl unassignedServices je Run //TODO: multiassigned analog. private static void checkServiceAssignment(Carriers carriers) { for (Carrier c : carriers.getCarriers().values()) { ArrayList<CarrierService> assignedServices = new ArrayList<CarrierService>(); ArrayList<CarrierService> multiassignedServices = new ArrayList<CarrierService>(); ArrayList<CarrierService> unassignedServices = new ArrayList<CarrierService>(); System.out.println("### Carrier: " + c.getId()); //Erfasse alle einer Tour zugehrigen (-> stattfindenden) Services for (ScheduledTour tour : c.getSelectedPlan().getScheduledTours()) { for (TourElement te : tour.getTour().getTourElements()) { if (te instanceof ServiceActivity) { CarrierService assigService = ((ServiceActivity) te).getService(); if (!assignedServices.contains(assigService)) { assignedServices.add(assigService); System.out.println("Assigned Service: " + assignedServices.toString()); } else { multiassignedServices.add(assigService); log.error("Service wurde von dem Carrier " + c.getId().toString() + " bereits angefahren: " + assigService.getId().toString()); } } } } //Nun prfe, ob alle definierten Service zugeordnet wurden for (CarrierService service : c.getServices()) { System.out.println("Service to Check: " + service.toString()); if (!assignedServices.contains(service)) { System.out.println("Service not assigned: " + service.toString()); unassignedServices.add(service); log.error("Service wird von Carrier " + c.getId().toString() + " NICHT bedient: " + service.getId().toString()); } else { System.out.println("Service was assigned: " + service.toString()); } } //Schreibe die mehrfach eingeplanten Services in Datei if (!multiassignedServices.isEmpty()) { try { FileWriter writer = new FileWriter(new File(TEMP_DIR + "#MultiAssignedServices.txt"), true); writer.write("#### Multi-assigned Services of Carrier: " + c.getId().toString() + System.getProperty("line.separator")); for (CarrierService s : multiassignedServices) { writer.write(s.getId().toString() + System.getProperty("line.separator")); } writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } } //Schreibe die nicht eingeplanten Services in Datei if (!unassignedServices.isEmpty()) { try { FileWriter writer = new FileWriter(new File(TEMP_DIR + "#UnassignedServices.txt"), true); writer.write("#### Unassigned Services of Carrier: " + c.getId().toString() + System.getProperty("line.separator")); for (CarrierService s : unassignedServices) { writer.write(s.getId().toString() + System.getProperty("line.separator")); } writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } } } //for(carriers) }
From source file:org.yestech.lib.io.FileSystemFileDownloadFilterUnitTest.java
@Test public void testDefaultSettings() throws IOException, ServletException { String testFileName = "unittest.tst"; File file = new File(System.getProperty("java.io.tmpdir"), testFileName); FileWriter writer = new FileWriter(file); String text = "testing download"; writer.write(text);/*w w w.j a va 2 s.co m*/ writer.flush(); writer.close(); // config.addInitParameter("deleteAfterDownload", "false"); // config.addInitParameter("baseDirectory", "false"); request.setParameter("file", testFileName); filter.doFilter(request, response, chain); assertEquals(text.length(), response.getContentLength()); assertEquals(text, response.getContentAsString()); assertTrue(file.exists()); file.delete(); }
From source file:info.balajeerc.spellspider.PageChecker.java
private PageChecker(OutputQueue outputQueue) { languageTool = null;//from w w w . j a va2 s . c o m this.outputQueue = outputQueue; outputFilePath = FilenameUtils.concat(outputQueue.getOutputDirectory(), "errors.csv"); try { languageTool = new JLanguageTool(Language.AMERICAN_ENGLISH); languageTool.activateDefaultPatternRules(); //Write the header for the output file FileWriter outFile = new FileWriter(outputFilePath); outFile.write("Url, Description, In Text, Error, Category\n"); outFile.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.powertac.producer.pvfarm.SolarFarmTest.java
@Test public void dataGenerateXML() throws IOException { Competition.newInstance("Solar famr xml"); SolarFarm farm = new SolarFarm(); PvPanel panel = new PvPanel(10, 22, 22, 180, 45, 0.35, -2); // 100 panels for (int i = 0; i < 100; i++) farm.addPanel(panel);//from w w w . j av a 2s . c om new File("data/").mkdir(); FileWriter fw = new FileWriter("data/solar-farm.xml"); XStream xstream = new XStream(); xstream.autodetectAnnotations(true); xstream.toXML(farm, fw); fw.close(); }
From source file:com.respam.comniq.models.MovieListParser.java
public void JSONWriter(JSONArray JSONarr) { try {/* w w w .j av a2 s . com*/ String path = System.getProperty("user.home") + File.separator + "comniq" + File.separator + "output"; File userOutDir = new File(path); if (userOutDir.exists()) { System.out.println(userOutDir + " already exists"); } else if (userOutDir.mkdirs()) { System.out.println(userOutDir + " was created"); } else { System.out.println(userOutDir + " was not created"); } FileWriter localList = new FileWriter(userOutDir + File.separator + "LocalList.json"); localList.write(JSONarr.toJSONString()); localList.flush(); localList.close(); System.out.println("Local Processing Complete"); } catch (IOException e) { e.printStackTrace(); } }
From source file:de.anhquan.codegen.ClassGenerator.java
protected void generate(String template, String outputDir, String fileName, String extension) throws IOException { File dir = new File(outputDir); if (!dir.exists()) { dir.mkdirs();/*w w w . j a v a 2 s .c om*/ } String filePath = outputDir + fileName + extension; FileWriter writer = new FileWriter(filePath); generate(template, writer); writer.close(); log.info("New file '" + filePath + "' has been genereated!"); }
From source file:au.org.ala.delta.util.LocalConfigFiles.java
private File getFile(String filename, String resourcePath) { File f = new File( String.format("%s%s%s", getSettingsDirectory().getAbsolutePath(), File.separator, filename)); if (!f.exists()) { InputStream is = LocalConfigFiles.class.getResourceAsStream(resourcePath); if (is != null) { try { List<String> lines = IOUtils.readLines(is); FileWriter writer = new FileWriter(f); IOUtils.writeLines(lines, LINE_ENDING, writer); writer.flush();//from w w w . j ava 2s. c o m writer.close(); } catch (IOException ioex) { throw new RuntimeException(ioex); } } } return f; }
From source file:com.ontotext.s4.multiThreadRequest.thread.ThreadClient.java
public void saveFile(String text, File file) throws IOException { FileWriter fileWriter = new FileWriter(file); fileWriter.append(text);/*from w w w . ja v a 2 s . c o m*/ fileWriter.close(); }