List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:generate.ShowConceptMapAction.java
public String execute() throws ClassNotFoundException, SQLException, IOException { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Major", "root", "pass"); PreparedStatement ps = con/* w ww . ja v a 2 s . c om*/ .prepareStatement("SELECT * from conceptmapdata where chapter_name = ? and section_name = ?"); ps.setString(1, getKey1()); ps.setString(2, getKey2()); System.out.println(getKey1()); System.out.println(getKey2()); ResultSet rs = ps.executeQuery(); while (rs.next()) { setData(rs.getString("output_text")); } try { FileWriter file = new FileWriter("/home/chanakya/NetBeansProjects/Concepto/web/new_graph.json"); file.write(getData()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } return SUCCESS; }
From source file:com.servioticy.dispatcher.bolts.BenchmarkBolt.java
@Override public void execute(Tuple input) { String suDoc = input.getStringByField("su"); Long stopTS = input.getLongByField("stopts") == null ? System.currentTimeMillis() : input.getLongByField("stopts"); String reason = input.getStringByField("reason") == null ? "timeout" : input.getStringByField("reason"); SensorUpdate su;/* w w w . ja v a 2 s. c o m*/ try { su = this.mapper.readValue(suDoc, SensorUpdate.class); int chainSize = su.getPathTimestamps() == null ? 0 : su.getPathTimestamps().size(); String csvLine = Long.toHexString(su.getOriginId()) + "," + su.getLastUpdate() + "," + stopTS + "," + reason + "," + chainSize; for (int i = 0; i < chainSize; i++) { csvLine += ","; csvLine += su.getPathTimestamps().get(i) + ","; csvLine += su.getTriggerPath().get(i).get(0) + "," + su.getTriggerPath().get(i).get(1); } File file = new File(dc.benchResultsDir + "/" + context.getThisTaskId() + ".csv"); file.createNewFile(); FileWriter writer = new FileWriter(file, true); writer.append(csvLine + "\n"); writer.flush(); writer.close(); } catch (Exception e) { // TODO Log the error e.printStackTrace(); collector.ack(input); return; } collector.ack(input); }
From source file:eu.eidas.node.auth.metadata.EidasNodeMetadataGeneratorTest.java
private void putMetadataInFile(String fileName, String metadataContent) { File f = new File(fileName); try {/* w w w .ja v a 2 s . com*/ FileWriter fw = new FileWriter(f); fw.append(metadataContent); fw.close(); } catch (IOException ioe) { fail("error writing metadata contents: " + ioe); } }
From source file:org.apache.qpid.disttest.charting.writer.ChartWriterTest.java
private void writeDummyContentToSummaryFileToEnsureItGetsOverwritten(File summaryFile) throws Exception { FileWriter writer = null; try {//from w w w . j a va 2 s. c om writer = new FileWriter(summaryFile); writer.write("dummy content"); writer.close(); } finally { if (writer != null) { writer.close(); } } }
From source file:com.playonlinux.bash.ScriptLegacy.java
@Override public void executeScript(PythonInterpreter pythonInterpreter) throws ScriptFailureException { // FIXME: Use the properties here Script playonlinuxBashInterpreter;/* ww w .ja va 2s .co m*/ File bashScriptFile; try { playonlinuxBashInterpreter = scriptFactory.createInstanceFromFile( new File("phoenicis-bash-support/src/main/python/PlayOnLinuxBashInterpreter.py")); bashScriptFile = File.createTempFile("script", "sh"); bashScriptFile.deleteOnExit(); FileWriter bashScriptWriter = new FileWriter(bashScriptFile); bashScriptWriter.write(this.getScriptContent()); bashScriptWriter.close(); } catch (IOException e) { throw new ScriptFailureException(e); } pythonInterpreter.set("__scriptToWrap__", bashScriptFile.getAbsolutePath()); playonlinuxBashInterpreter.executeScript(pythonInterpreter); }
From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.FileUtilityTest.java
@Test public void testRevertLatestBackupFiles() throws IOException, InterruptedException, FileUtilityException { LOGGER.debug("REVERT TEST STARTING"); Date latestDate = new Date(); fileUtility.copyBackupFile(TEMP_DIR, "config", "tempfile2.tmp", latestDate); File alterFile = new File(TEMP_DIR + "/config/tempfile2.tmp"); LOGGER.debug("ALTER FILE - " + alterFile.getAbsolutePath() + " - Exists: " + alterFile.isFile()); FileWriter writer = new FileWriter(alterFile); writer.append("THIS IS A NEWER FILE"); writer.close(); FileReader reader = new FileReader(alterFile); BufferedReader br = new BufferedReader(reader); String fileText = br.readLine(); reader.close();//from ww w . j a v a2 s .c o m assertEquals("This text should be the same.", "THIS IS A NEWER FILE", fileText); Set<String> latestDirs = fileUtility.getLatestBackupDirectories(TEMP_DIR); String highestDirectory = ((TreeSet<String>) latestDirs).last(); fileUtility.revertToBackupFiles(TEMP_DIR, highestDirectory); alterFile = new File(TEMP_DIR + "/config/tempfile2.tmp"); LOGGER.debug("ALTER FILE After - " + alterFile.getAbsolutePath() + " - Exists: " + alterFile.isFile()); reader = new FileReader(alterFile); br = new BufferedReader(reader); fileText = br.readLine(); reader.close(); assertEquals("The text in the file should be the same.", FILE2_TEXT, fileText); }
From source file:com.zimbra.qa.unittest.TestImap.java
private static Literal message(int size) throws IOException { File file = File.createTempFile("msg", null); file.deleteOnExit();/*from ww w . j a va2s . c o m*/ FileWriter out = new FileWriter(file); try { out.write(simpleMessage("test message")); for (int i = 0; i < size; i++) { out.write('X'); if (i % 72 == 0) { out.write("\r\n"); } } } finally { out.close(); } return new Literal(file, true); }
From source file:com.mycompany.rent.controllers.MapController.java
@RequestMapping(value = "/data", method = RequestMethod.GET) public File homePage(Map model) throws IOException { List<ForRent> allRentals = new ArrayList(); allRentals = forRentDao.allRentals(); JSONObject responseDetailsJson = new JSONObject(); JSONArray array = new JSONArray(); for (ForRent f : allRentals) { array.add(f.getLat());//w ww .j av a 2s. co m array.add(f.getLon()); } responseDetailsJson.put("data", (Object) array);//Here you can see the data in json format File file = new File("/home/brennan/_repos/rent/src/main/webapp/json/data.json"); String path = file.getPath(); try { // Writing to a file file.createNewFile(); FileWriter fileWriter = new FileWriter(file); fileWriter.write(responseDetailsJson.toJSONString()); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { } FileReader fr = new FileReader(file); return file; }
From source file:com.telefonica.euro_iaas.sdc.puppetwrapper.services.impl.FileAccessServiceImpl.java
public Node generateManifestFile(String nodeName) throws IOException { logger.info("creating Manifest file for node: " + nodeName); Node node = catalogManager.getNode(nodeName); String fileContent = catalogManager.generateManifestStr(nodeName); String path = defaultManifestsPath + node.getGroupName(); try {// ww w . java2 s . c om File f = new File(path); f.mkdirs(); f.createNewFile(); } catch (IOException ex) { logger.debug("Error creating manifest paths and pp file", ex); throw new IOException("Error creating manifest paths and pp file"); } try { FileWriter fw = new FileWriter(path + "/" + node.getId() + ".pp", false); fw.write(fileContent); fw.close(); } catch (IOException ex) { logger.debug("Error creating manifest paths and pp file", ex); throw new IOException("Error creating manifest paths and pp file"); } logger.debug("Manifest file created"); return node; }
From source file:net.ripe.rpki.commons.util.CsvFormatter.java
public void print(File outputFile) throws IOException { FileWriter fileWriter = new FileWriter(outputFile); print(fileWriter, true);//from www. j a va 2 s . c o m fileWriter.close(); }