List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:edu.missouri.bas.bluetooth.equivital.EquivitalRunnable.java
protected void writeToFile(File f, String toWrite) throws IOException { FileWriter fw = new FileWriter(f, true); fw.write(toWrite + '\n'); fw.flush();/*from www .j a va2 s . com*/ fw.close(); }
From source file:bigtweet.model.StudyingBeacons.java
/** * Extra ouput file to generate a chart * call plotBeaconStudy in R project to obtain chart *///from ww w .j av a 2 s . co m private void generateBatchOuputForChart(JSONArray parametersValues, int parametersValuesIndex, double meanEndorsers) { JSONObject parameters = (JSONObject) parametersValues.get(parametersValuesIndex);//parameters JSONObject aux = new JSONObject(); aux.put("links", parameters.get("beaconLinksNumber")); aux.put("centrality", parameters.get("beaconLinksCentrality")); DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US); DecimalFormat df = new DecimalFormat("0.000", otherSymbols); aux.put("meanEndorsers", df.format(meanEndorsers)); JSONForChart.add(aux); //write json file FileWriter file; try { file = new FileWriter(batchOutputFileForChart); file.write(JSONForChart.toJSONString()); file.flush(); file.close(); } catch (Exception ex) { Logger.getLogger(BTSimBatch.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.powertac.producer.hydro.DamTest.java
@Test public void dataGenerateXml() throws IOException { Curve volume = new Curve(); volume.add(0, 0);/*w w w . jav a 2s. co m*/ volume.add(100000000.0, 56.4); volume.add(300000000.0, 95.7); volume.add(400000000.0, 105); volume.add(600000000.0, 123); volume.add(800000000.0, 135); volume.value(5000); double[] x = { 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.30, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.40, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.50, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.60, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.70, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.80, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.90, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1 }; double[] y = { 0.54, 0.567510059257987, 0.593427468223978, 0.617806965819306, 0.640703290965304, 0.662171182583305, 0.682265379594641, 0.701040620920646, 0.718551645482652, 0.734853192201992, 0.75, 0.764046807798008, 0.777048354517348, 0.789059379079354, 0.800134620405359, 0.810328817416695, 0.819696709034696, 0.828293034180694, 0.836172531776022, 0.843389940742013, 0.85, 0.856052709549983, 0.861579113706630, 0.866605517863277, 0.871158227413260, 0.875263547749914, 0.878947784266575, 0.882237242356579, 0.885158227413260, 0.887737044829955, 0.89, 0.891972354002061, 0.893675190656132, 0.895128549467537, 0.896352469941601, 0.897366991583648, 0.898192153899004, 0.898847996392992, 0.899354558570938, 0.899731879938166, 0.90, 0.900177874441773, 0.900280123668842, 0.900320284266575, 0.900311892820337, 0.900268485915493, 0.900203600137410, 0.900130772071453, 0.900063538302989, 0.900015435417382, 0.90, 0.900026148230849, 0.900084314668499, 0.900160313466163, 0.900239958777053, 0.900309064754380, 0.900353445551357, 0.900358915321196, 0.900311288217108, 0.900196378392305, 0.90, 0.899712532634833, 0.899342617657162, 0.898903461868774, 0.898408272071453, 0.897870255066987, 0.897302617657163, 0.896718566643765, 0.896131308828581, 0.895554051013397, 0.895000000000000, 0.894478721229818, 0.893985214702851, 0.893510839058743, 0.893046952937135, 0.892584914977671, 0.892116083819993, 0.891631818103744, 0.891123476468568, 0.890582417554105, 0.89, 0.889367582445895, 0.888676523531433, 0.887918181896256, 0.887083916180007, 0.886165085022329, 0.885153047062865, 0.884039160941257, 0.882814785297149, 0.881471278770182, 0.88 }; Curve efficiency = new Curve(); for (int i = 0; i < x.length; i++) { efficiency.add(x[i], y[i]); } efficiency.value(0.5); Curve inputFlow = new Curve(); inputFlow.add(1, 420); inputFlow.add(60, 400); inputFlow.add(90, 480); inputFlow.add(120, 700); inputFlow.add(150, 1200); inputFlow.add(180, 1800); inputFlow.add(210, 2000); inputFlow.add(240, 2000); inputFlow.add(270, 2000); inputFlow.add(300, 1800); inputFlow.add(330, 1100); inputFlow.add(365, 600); inputFlow.value(125); Competition.newInstance("Inverse curve test"); Dam dam = new Dam(inputFlow, 100, 600, efficiency, volume, 600000000.0, -500000, 0.95); new File("data/").mkdir(); FileWriter fw = new FileWriter("data/dam.xml"); XStream xstream = new XStream(); xstream.autodetectAnnotations(true); xstream.toXML(dam, fw); fw.close(); }
From source file:de.uzk.hki.da.grid.CTIrodsCommandLineConnector.java
private File createTestFile() throws IOException { new File(tmpDir).mkdir(); File temp = new File(tmpDir + "urn.tar"); FileWriter writer = new FileWriter(temp, false); writer.write("Hallo Wie gehts?"); writer.close(); return temp;/*w w w . j ava 2 s . c o m*/ }
From source file:net.blogracy.controller.FileSharing.java
public void addFeedEntry(String id, String text, File attachment) { try {//from w ww .j av a 2s .c o m String hash = hash(text); File textFile = new File(CACHE_FOLDER + File.separator + hash + ".txt"); FileWriter w = new FileWriter(textFile); w.write(text); w.close(); String textUri = seed(textFile); String attachmentUri = null; if (attachment != null) { attachmentUri = seed(attachment); } final List<ActivityEntry> feed = getFeed(id); final ActivityEntry entry = new ActivityEntryImpl(); entry.setVerb("post"); entry.setUrl(textUri); entry.setPublished(ISO_DATE_FORMAT.format(new Date())); entry.setContent(text); if (attachment != null) { ActivityObject enclosure = new ActivityObjectImpl(); enclosure.setUrl(attachmentUri); entry.setObject(enclosure); } feed.add(0, entry); final File feedFile = new File(CACHE_FOLDER + File.separator + id + ".json"); JSONArray items = new JSONArray(); for (int i = 0; i < feed.size(); ++i) { JSONObject item = new JSONObject(feed.get(i)); items.put(item); } JSONObject db = new JSONObject(); db.put("items", items); FileWriter writer = new FileWriter(feedFile); db.write(writer); writer.close(); String feedUri = seed(feedFile); DistributedHashTable.getSingleton().store(id, feedUri, entry.getPublished()); } catch (Exception e) { e.printStackTrace(); } }
From source file:icevaluation.ICEvaluation.java
public void startICEval() { loadkeyInfo();//w w w . ja v a2 s.c o m System.out.println("Total Key: " + totalkey); //String queryOriginal = "sports game"; //String queryCover = "jack raihanee"; BufferedReader reader = null; try { File file = new File("data/topic/QueryLogs.txt"); reader = new BufferedReader(new FileReader(file)); String line; line = reader.readLine(); if (line == null) { System.out.println("Please uptate query file correctly"); return; } int numCoverQ = Integer.parseInt(line); String originQuery = ""; String coverQuery = ""; while ((line = reader.readLine()) != null) {//original query //System.out.println("Original: "+line); originQuery = line; for (int i = 0; i < numCoverQ; i++) { line = reader.readLine(); if (line == null) { System.out.println("Please uptate query file correctly"); return; } coverQuery = line; double IC = getIC(originQuery, coverQuery); FileWriter fw; fw = new FileWriter("data/topic/IC_topic.txt", true); fw.write(IC + "\n"); fw.close(); System.out.println(IC); } } } catch (IOException e) { e.printStackTrace(); } finally { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } writeKeyInfoBack(); System.out.println("Key status write succesfully"); } }
From source file:org.powertac.producer.hydro.RunOfRiverTest.java
@Test public void dataGenerateXml() throws IOException { Curve inputFlow = new Curve(); double[] y = { 150.93, 139.35, 178.59, 174.37, 136.75, 133.64, 128.89, 127.25, 128.73, 144.62, 156.51, 181.89, 141.64, 159.33, 149.30, 121.12, 179.54, 232.12, 258.08, 237.18, 220.32, 230.75, 256.72, 257.83, 251.68, 229.52, 252.37, 251.43, 222.80, 187.57, 232.88, 226.58, 207.18, 197.13, 199.27, 163.70, 150.40, 155.70, 211.47, 215.75, 217.23, 219.50, 213.97, 177.71, 203.06, 221.15, 215.45, 220.16, 215.02, 211.03, 200.98, 194.78, 183.42, 214.86, 190.08, 192.33, 183.75, 194.89, 210.47, 222.11, 214.89, 203.90, 217.38, 186.53, 184.18, 213.71, 191.74, 224.60, 201.29, 204.02, 227.96, 185.46, 220.18, 209.19, 182.50, 224.28, 229.55, 219.83, 198.23, 174.27, 198.77, 237.54, 227.49, 225.27, 213.58, 242.83, 208.50, 225.17, 228.20, 244.45, 293.15, 319.49, 354.15, 351.33, 374.75, 348.11, 303.55, 278.62, 314.15, 319.30, 289.06, 299.55, 278.69, 261.02, 275.69, 202.89, 242.91, 267.86, 251.20, 270.84, 270.20, 282.11, 255.64, 243.84, 253.75, 234.95, 261.82, 257.20, 226.31, 219.35, 257.10, 241.93, 246.79, 250.24, 230.08, 254.66, 231.22, 238.59, 267.91, 289.35, 248.45, 270.34, 335.20, 338.03, 366.69, 423.45, 442.26, 444.96, 449.96, 451.19, 461.15, 457.13, 471.72, 477.84, 476.64, 462.09, 486.46, 491.88, 497.34, 494.46, 491.72, 486.49, 480.88, 481.12, 498.41, 493.33, 491.76, 482.40, 492.29, 494.48, 494.78, 491.09, 478.23, 482.07, 489.95, 489.84, 492.75, 488.38, 462.97, 440.38, 426.90, 428.48, 440.70, 432.90, 480.63, 451.82, 423.08, 396.45, 394.52, 381.41, 388.90, 418.33, 428.18, 405.74, 409.38, 359.30, 370.30, 385.97, 376.35, 376.27, 365.44, 343.22, 306.27, 294.97, 320.97, 331.74, 289.69, 269.50, 289.15, 279.23, 283.67, 262.26, 259.69, 255.34, 244.33, 244.51, 236.17, 226.47, 238.11, 209.22, 203.91, 225.66, 221.99, 191.54, 198.33, 205.45, 194.11, 171.04, 181.43, 197.49, 185.96, 194.35, 196.43, 200.32, 160.97, 149.27, 188.71, 189.23, 194.86, 189.84, 195.41, 175.54, 157.37, 161.75, 173.32, 186.87, 195.82, 167.11, 169.41, 148.44, 146.42, 140.38, 165.04, 143.84, 123.20, 101.61, 97.750, 116.29, 117.95, 124.26, 123.54, 139.54, 120.89, 110.25, 128.37, 108.38, 104.58, 109.73, 116.92, 109.42, 104.07, 102.33, 122.03, 123.26, 104.29, 103.62, 91.750, 96.140, 116.95, 109.68, 110.71, 101.40, 105.67, 78.380, 80.710, 90.290, 100.03, 108.30, 117.16, 96.900, 93.890, 94.100, 129.53, 114.42, 100.36, 113.98, 133.06, 136.70, 127.35, 122.11, 119.30, 103.62, 114.25, 118.22, 115.95, 88.670, 107.94, 118.67, 104.45, 131.19, 126.84, 121.48, 94.980, 96.540, 131.90, 131.34, 124.03, 116.47, 117.32, 118.13, 117.99, 132.40, 116.32, 115.21, 126.75, 109.51, 112, 129.35, 116.82, 143.01, 132.10, 127.81, 121.95, 135.30, 131.32, 127.96, 116.67, 114.47, 113.17, 117.26, 109.72, 123.01, 121.85, 127.22, 125.33, 122.18, 122.19, 125.14, 136.47, 134.70, 139.05, 131.83, 136.58, 138.34, 122.26, 140.76, 130.10, 141.18, 132.31, 117.35, 133.08, 112.71, 120.88, 134.15, 121.01, 132.05, 124.80, 125.95, 118.71, 131.57, 136.90, 127.24, 112.67, 126.07, 123.33 }; for (int i = 0; i < 365; i++) { inputFlow.add(i, y[i]);/*from w ww . j a v a 2 s .c om*/ } inputFlow.value(300); double[] x = { 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.30, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.40, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.50, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.60, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.70, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.80, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.90, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1 }; double[] y2 = { 0.54, 0.567510059257987, 0.593427468223978, 0.617806965819306, 0.640703290965304, 0.662171182583305, 0.682265379594641, 0.701040620920646, 0.718551645482652, 0.734853192201992, 0.75, 0.764046807798008, 0.777048354517348, 0.789059379079354, 0.800134620405359, 0.810328817416695, 0.819696709034696, 0.828293034180694, 0.836172531776022, 0.843389940742013, 0.85, 0.856052709549983, 0.861579113706630, 0.866605517863277, 0.871158227413260, 0.875263547749914, 0.878947784266575, 0.882237242356579, 0.885158227413260, 0.887737044829955, 0.89, 0.891972354002061, 0.893675190656132, 0.895128549467537, 0.896352469941601, 0.897366991583648, 0.898192153899004, 0.898847996392992, 0.899354558570938, 0.899731879938166, 0.90, 0.900177874441773, 0.900280123668842, 0.900320284266575, 0.900311892820337, 0.900268485915493, 0.900203600137410, 0.900130772071453, 0.900063538302989, 0.900015435417382, 0.90, 0.900026148230849, 0.900084314668499, 0.900160313466163, 0.900239958777053, 0.900309064754380, 0.900353445551357, 0.900358915321196, 0.900311288217108, 0.900196378392305, 0.90, 0.899712532634833, 0.899342617657162, 0.898903461868774, 0.898408272071453, 0.897870255066987, 0.897302617657163, 0.896718566643765, 0.896131308828581, 0.895554051013397, 0.895000000000000, 0.894478721229818, 0.893985214702851, 0.893510839058743, 0.893046952937135, 0.892584914977671, 0.892116083819993, 0.891631818103744, 0.891123476468568, 0.890582417554105, 0.89, 0.889367582445895, 0.888676523531433, 0.887918181896256, 0.887083916180007, 0.886165085022329, 0.885153047062865, 0.884039160941257, 0.882814785297149, 0.881471278770182, 0.88 }; Curve efficiency = new Curve(); for (int i = 0; i < x.length; i++) { efficiency.add(x[i], y2[i]); } efficiency.value(0.5); Competition.newInstance("run of river"); RunOfRiver river = new RunOfRiver(inputFlow, 20, 500, efficiency, 1000000, 80, 0.95, -300000); new File("data/").mkdir(); FileWriter fw = new FileWriter("data/runoftheriver.xml"); XStream xstream = new XStream(); xstream.autodetectAnnotations(true); xstream.toXML(river, fw); fw.close(); }
From source file:com.github.aneveux.docukes.generators.MarkdownGenerator.java
/** * Creates a markdown file in the target repository containing some * documentation generated from the specified Java class * /*w ww . java2 s. c o m*/ * @param clazz * a Java class containing some cukes annotations * @param methods * the methods of the Java class which are actually annotated * with Cukes * @param withDate * defines if the markdown file should contain the time on which * generation has been performed */ public void write(JavaClassSource clazz, List<MethodSource<JavaClassSource>> methods, boolean withDate) { final File file = new File(target.getPath() + "/" + clazz.getName() + ".md"); try { final FileWriter writer = new FileWriter(file); writer.write(generateContent(clazz, methods, withDate)); writer.flush(); writer.close(); } catch (final IOException ioe) { ioe.printStackTrace(); } }
From source file:com.photon.phresco.plugins.PhpPackage.java
private void writeBuildInfo(boolean isBuildSuccess) throws MojoExecutionException { try {//from w ww . j a va2 s . c om if (buildNumber != null) { buildNo = Integer.parseInt(buildNumber); } PluginUtils pu = new PluginUtils(); BuildInfo buildInfo = new BuildInfo(); List<String> envList = pu.csvToList(environmentName); if (buildNo > 0) { buildInfo.setBuildNo(buildNo); } else { buildInfo.setBuildNo(nextBuildNo); } buildInfo.setTimeStamp(getTimeStampForDisplay(currentDate)); if (isBuildSuccess) { buildInfo.setBuildStatus(SUCCESS); } else { buildInfo.setBuildStatus(FAILURE); } buildInfo.setBuildName(zipName); buildInfo.setEnvironments(envList); buildInfoList.add(buildInfo); Gson gson = new Gson(); FileWriter writer = new FileWriter(buildInfoFile); gson.toJson(buildInfoList, writer); writer.close(); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:org.saiku.web.rest.resources.BasicRepositoryResource.java
/** * //from w ww. j av a 2 s .com * @param queryName - The name of the query. * @param newName - The saved query name. * @return An OK Status, if the save was good, otherwise a NOT FOUND Status when not saved properly. */ @POST @Produces({ "application/json" }) @Path("/{queryname}") public Status saveQuery(@PathParam("queryname") String queryName, @FormParam("newname") String newName) { try { String xml = olapQueryService.getQueryXml(queryName); if (newName != null) { queryName = newName; } if (repo != null && xml != null) { if (!queryName.endsWith(".saiku")) { queryName += ".saiku"; } String uri = repo.getName().getPath(); if (!uri.endsWith("" + File.separatorChar)) { uri += File.separatorChar; } File queryFile = new File(uri + URLDecoder.decode(queryName, "UTF-8")); if (queryFile.exists()) { queryFile.delete(); } else { queryFile.createNewFile(); } FileWriter fw = new FileWriter(queryFile); fw.write(xml); fw.close(); return (Status.OK); } else { throw new Exception("Cannot save query because repo or xml is null repo(" + (repo == null) + ") xml(" + (xml == null) + " )"); } } catch (Exception e) { log.error("Cannot save query (" + queryName + ")", e); return (Status.NOT_FOUND); } }