List of usage examples for java.io FileWriter flush
public void flush() throws IOException
From source file:model.experiments.tuningRuns.CompetitiveAveragingGridSearch.java
public static void main(String[] args) throws IOException { FileWriter writer;/* = new FileWriter(Paths.get("runs", "tunings","averaging", "averagingTuning.csv").toFile()); //from w w w.j a va 2 s . c om for(float hrWeight= .1f; hrWeight<1f;hrWeight= round(hrWeight+.1f,1)) for(float salesWeight= .1f; salesWeight<1f;salesWeight= round(salesWeight+.1f,1)) for(PriceAverager.NoTradingDayPolicy hrPolicy : PriceAverager.NoTradingDayPolicy.values()) for(PriceAverager.NoTradingDayPolicy salesPolicy : PriceAverager.NoTradingDayPolicy.values()) { final CompetitiveAveragingResult r = exponentialRuns(hrWeight, hrPolicy, salesWeight, salesPolicy,20); final String line = hrWeight + "," + hrPolicy + "," + salesWeight + "," + salesPolicy + "," + r.getPrice() + "," + r.getQuantity() + "," + r.getStd(); System.out.println(line); writer.write(line+"\n"); } */ writer = new FileWriter(Paths.get("runs", "tunings", "averaging", "intervalTuning.csv").toFile()); for (float hrWeight = .1f; hrWeight < 1f; hrWeight = round(hrWeight + .1f, 1)) for (float salesWeight = .1f; salesWeight < 1f; salesWeight = round(salesWeight + .1f, 1)) { final CompetitiveAveragingResult r = intervalRuns(hrWeight, salesWeight); final String line = hrWeight + "," + salesWeight + "," + r.getPrice() + "," + r.getQuantity() + "," + r.getStd(); System.out.println(line); writer.write(line + "\n"); writer.flush(); } writer.close(); writer = new FileWriter(Paths.get("runs", "tunings", "averaging", "weightedAveragingTuning.csv").toFile()); for (int hrDays = 1; hrDays <= 10; hrDays++) for (int salesDays = 1; salesDays <= 10; salesDays++) for (boolean hrDecorated : new boolean[] { false, true }) for (boolean salesDecorated : new boolean[] { false, true }) { final CompetitiveAveragingResult r = weightedRun(hrDays, salesDays, hrDecorated, salesDecorated); final String line = hrDays + "," + salesDays + "," + hrDecorated + "," + salesDecorated + "," + r.getPrice() + "," + r.getQuantity() + "," + r.getStd(); System.out.println(line); writer.write(line + "\n"); writer.flush(); } writer = new FileWriter(Paths.get("runs", "tunings", "averaging", "doesSpeedMatters.csv").toFile()); /* for(int speed=1; speed<100; speed++) { final CompetitiveAveragingResult r = exponentialRuns(.8f, PriceAverager.NoTradingDayPolicy.COUNT_AS_LAST_CLOSING_PRICE, .8f, PriceAverager.NoTradingDayPolicy.COUNT_AS_LAST_CLOSING_PRICE, speed); final String line = speed + "," + r.getPrice() + "," + r.getQuantity() + "," + r.getStd(); System.out.println(line); writer.write(line+"\n"); } */ }
From source file:com.thed.zapi.cloud.sample.CycleExecutionReportByVersion.java
public static void main(String[] args) throws JSONException, URISyntaxException, ParseException, IOException { String API_GET_EXECUTIONS = "{SERVER}/public/rest/api/1.0/executions/search/cycle/"; String API_GET_CYCLES = "{SERVER}/public/rest/api/1.0/cycles/search?"; // Delimiter used in CSV file final String NEW_LINE_SEPARATOR = "\n"; final String fileName = "F:\\cycleExecutionReport.csv"; /** Declare JIRA,Zephyr URL,access and secret Keys */ // JIRA Cloud URL of the instance String jiraBaseURL = "https://demo.atlassian.net"; // Replace zephyr baseurl <ZAPI_Cloud_URL> shared with the user for ZAPI Cloud Installation String zephyrBaseUrl = "<ZAPI_Cloud_URL>"; // zephyr accessKey , we can get from Addons >> zapi section String accessKey = "YjE2MjdjMGEtNzExNy0zYjY1LWFkMzQtNjcwMDM3OTljFkbWluIGFkbWlu"; // zephyr secretKey , we can get from Addons >> zapi section String secretKey = "qufnbimi96Ob2hq3ISF08yZ8Qw4c1eHGeGlk"; /** Declare parameter values here */ String userName = "admin"; String versionId = "-1"; String projectId = "10100"; String projectName = "Support"; String versionName = "Unscheduled"; ZFJCloudRestClient client = ZFJCloudRestClient.restBuilder(zephyrBaseUrl, accessKey, secretKey, userName) .build();/*from w w w .jav a 2 s . c om*/ /** * Get List of Cycles by Project and Version */ final String getCyclesUri = API_GET_CYCLES.replace("{SERVER}", zephyrBaseUrl) + "projectId=" + projectId + "&versionId=" + versionId; Map<String, String> cycles = getCyclesByProjectVersion(getCyclesUri, client, accessKey); // System.out.println("cycles :"+ cycles.toString()); /** * Iterating over the Cycles and writing the report to CSV * */ FileWriter fileWriter = null; System.out.println("Writing CSV file....."); try { fileWriter = new FileWriter(fileName); // Write the CSV file header fileWriter.append("Cycle Execution Report By Version and Project"); fileWriter.append(NEW_LINE_SEPARATOR); fileWriter.append("PROJECT:" + "," + projectName); fileWriter.append(NEW_LINE_SEPARATOR); fileWriter.append("VERSION:" + "," + versionName); fileWriter.append(NEW_LINE_SEPARATOR); JSONArray executions; int totalUnexecutedCount = 0; int totalExecutionCount = 0; for (String key : cycles.keySet()) { int executionCount = 0; int unexecutedCount = 0; final String getExecutionsUri = API_GET_EXECUTIONS.replace("{SERVER}", zephyrBaseUrl) + key + "?projectId=" + projectId + "&versionId=" + versionId; fileWriter.append("Cycle:" + "," + cycles.get(key)); fileWriter.append(NEW_LINE_SEPARATOR); executions = getExecutionsByCycleId(getExecutionsUri, client, accessKey); // System.out.println("executions :" + executions.toString()); HashMap<String, Integer> counter = new HashMap<String, Integer>(); String[] statusName = new String[executions.length()]; for (int i = 0; i < executions.length(); i++) { JSONObject executionObj = executions.getJSONObject(i).getJSONObject("execution"); // System.out.println("executionObj // "+executionObj.toString()); JSONObject statusObj = executionObj.getJSONObject("status"); // System.out.println("statusObj :"+statusObj.toString()); statusName[i] = statusObj.getString("name"); } if (statusName.length != 0) { // System.out.println(statusName.toString()); for (String a : statusName) { if (counter.containsKey(a)) { int oldValue = counter.get(a); counter.put(a, oldValue + 1); } else { counter.put(a, 1); } } for (String status : counter.keySet()) { fileWriter.append(" " + "," + " " + "," + status + "," + counter.get(status)); fileWriter.append(NEW_LINE_SEPARATOR); if (status.equalsIgnoreCase("UNEXECUTED")) { unexecutedCount += counter.get(status); } else { executionCount += counter.get(status); } } } totalExecutionCount += executionCount; totalUnexecutedCount += unexecutedCount; fileWriter.append(NEW_LINE_SEPARATOR); } fileWriter.append(NEW_LINE_SEPARATOR); fileWriter.append("TOTAL CYCLES:" + "," + cycles.size()); fileWriter.append(NEW_LINE_SEPARATOR); fileWriter.append("TOTAL EXECUTIONS:" + "," + totalExecutionCount); fileWriter.append(NEW_LINE_SEPARATOR); fileWriter.append("TOTAL ASSIGNED:" + "," + (totalUnexecutedCount + totalExecutionCount)); System.out.println("CSV file was created successfully !!!"); } catch (Exception e) { System.out.println("Error in CsvFileWriter !!!"); e.printStackTrace(); } finally { try { fileWriter.flush(); fileWriter.close(); } catch (IOException e) { System.out.println("Error while flushing/closing fileWriter !!!"); e.printStackTrace(); } } }
From source file:enrichment.Disambiguate.java
/**prerequisites: * cd silk_2.5.3/*_links/*from ww w.j a v a2 s .co m*/ * cat *.nt|sort -t' ' -k3 > $filename * * @param args $filename * @throws IOException * @throws URISyntaxException */ public static void main(String[] args) { File file = new File(args[0]); if (file.isDirectory()) { args = file.list(new OnlyExtFilenameFilter("nt")); } BufferedReader in; for (int q = 0; q < args.length; q++) { String filename = null; if (file.isDirectory()) { filename = file.getPath() + File.separator + args[q]; } else { filename = args[q]; } try { FileWriter output = new FileWriter(filename + "_disambiguated.nt"); String prefix = "@prefix rdrel: <http://rdvocab.info/RDARelationshipsWEMI/> .\n" + "@prefix dbpedia: <http://de.dbpedia.org/resource/> .\n" + "@prefix frbr: <http://purl.org/vocab/frbr/core#> .\n" + "@prefix lobid: <http://lobid.org/resource/> .\n" + "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" + "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n" + "@prefix mo: <http://purl.org/ontology/mo/> .\n" + "@prefix wikipedia: <https://de.wikipedia.org/wiki/> ."; output.append(prefix + "\n\n"); in = new BufferedReader(new InputStreamReader(new FileInputStream(filename))); HashMap<String, HashMap<String, ArrayList<String>>> hm = new HashMap<String, HashMap<String, ArrayList<String>>>(); String s; HashMap<String, ArrayList<String>> hmLobid = new HashMap<String, ArrayList<String>>(); Stack<String> old_object = new Stack<String>(); while ((s = in.readLine()) != null) { String[] triples = s.split(" "); String object = triples[2].substring(1, triples[2].length() - 1); if (old_object.size() > 0 && !old_object.firstElement().equals(object)) { hmLobid = new HashMap<String, ArrayList<String>>(); old_object = new Stack<String>(); } old_object.push(object); String subject = triples[0].substring(1, triples[0].length() - 1); System.out.print("\nSubject=" + object); System.out.print("\ntriples[2]=" + triples[2]); hmLobid.put(subject, getAllCreators(new URI(subject))); hm.put(object, hmLobid); } // get all dbpedia resources for (String key_one : hm.keySet()) { System.out.print("\n==============\n==== " + key_one + "\n==============="); int resources_cnt = hm.get(key_one).keySet().size(); ArrayList<String>[] creators = new ArrayList[resources_cnt]; HashMap<String, Integer> creators_backed = new HashMap<String, Integer>(); int x = 0; // get all lobid_resources subsumed under the dbpedia resource for (String subject_uri : hm.get(key_one).keySet()) { creators[x] = new ArrayList<String>(); System.out.print("\n subject_uri=" + subject_uri); Iterator<String> ite = hm.get(key_one).get(subject_uri).iterator(); int y = 0; // get all creators of the lobid resource while (ite.hasNext()) { String creator = ite.next(); System.out.print("\n " + creator); if (creators_backed.containsKey(creator)) { y = creators_backed.get(creator); } else { y = creators_backed.size(); creators_backed.put(creator, y); } while (creators[x].size() <= y) { creators[x].add("-"); } creators[x].set(y, creator); y++; } x++; } if (creators_backed.size() == 1) { System.out .println("\n" + "Every resource pointing to " + key_one + " has the same creator!"); for (String key_two : hm.get(key_one).keySet()) { output.append("<" + key_two + "> rdrel:workManifested <" + key_one + "> .\n"); output.append("<" + key_two + "> mo:wikipedia <" + key_one.replaceAll("dbpedia\\.org/resource", "wikipedia\\.org/wiki") + "> .\n"); } } /*else { for (int a = 0; a < creators.length; a++) { System.out.print(creators[a].toString()+","); } }*/ } output.flush(); if (output != null) { output.close(); } } catch (Exception e) { System.out.print("Exception while working on " + filename + ": \n"); e.printStackTrace(System.out); } } }
From source file:Main.java
public static boolean putFileContent(File file, String content) throws IOException { FileWriter writer = new FileWriter(file); writer.write(content);/*from w ww .j av a2 s .co m*/ writer.flush(); writer.close(); return false; }
From source file:Main.java
/** * Writes the given string into the given file. * /*www .j av a 2s . c om*/ * @param contents * String representing the file contents. * @param filename * Name of the file to be written. * @throws IOException */ public static void writeFile(String contents, String filename) throws IOException { FileWriter fw = new FileWriter(filename); fw.write(contents); fw.flush(); fw.close(); }
From source file:Main.java
public static void writeToFile(String fileName, String toWrite) throws IOException { File dir = new File(PHONE_BASE_PATH); if (!dir.exists()) { dir.mkdirs();// w w w . ja v a 2s .c o m } File f = new File(PHONE_BASE_PATH, fileName); FileWriter fw = new FileWriter(f, true); fw.write(toWrite + '\n'); fw.flush(); fw.close(); f = null; }
From source file:Main.java
static void setSetting(String name, String data) { try {//from www. ja va 2 s . com File root = new File(Environment.getExternalStorageDirectory().toString(), ".Instagram"); if (!root.exists()) { root.mkdirs(); } File gpxfile = new File(root, name + ".txt"); FileWriter writer = new FileWriter(gpxfile); writer.append(data); writer.flush(); writer.close(); } catch (IOException e) { } }
From source file:Main.java
public static void xmlToFile(Document doc, File file) { String xmlString = xmlToString(doc); try {//from w ww.j a va 2s . c o m FileWriter w = new FileWriter(file); w.write(xmlString); w.flush(); w.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean writeLineToFile(File file, String line, boolean append) { try {//from w w w. j a v a 2 s . c o m FileWriter fileWriter = new FileWriter(file, append); fileWriter.append(line + "\r\n"); fileWriter.flush(); fileWriter.close(); return true; } catch (IOException e) { e.printStackTrace(); return false; } }
From source file:naftoreiclag.villagefive.SaveLoad.java
public static void save(World data) throws IOException { JSONObject obj = new JSONObject(); obj.put("world", data); FileWriter fw = new FileWriter(new File("saves/save.json")); obj.writeJSONString(fw);/*from w w w . j a v a 2s . c om*/ fw.flush(); }