List of usage examples for java.nio.file Files newBufferedWriter
public static BufferedWriter newBufferedWriter(Path path, OpenOption... options) throws IOException
From source file:eu.itesla_project.modules.validation.OfflineValidationTool.java
private static void writeSynthesisFile(Map<RuleId, Map<String, AtomicInteger>> synthesisPerRule, List<String> categories, Path synthesisFile) throws IOException { System.out.println("writing " + synthesisFile + "..."); try (BufferedWriter writer = Files.newBufferedWriter(synthesisFile, StandardCharsets.UTF_8)) { writer.write("rule"); for (String c : categories) { writer.write(CSV_SEPARATOR); writer.write(c);/* w w w.j ava 2 s .co m*/ } writer.newLine(); for (Map.Entry<RuleId, Map<String, AtomicInteger>> e : synthesisPerRule.entrySet()) { RuleId ruleId = e.getKey(); Map<String, AtomicInteger> count = e.getValue(); writer.write(ruleId.toString()); for (String c : categories) { writer.write(CSV_SEPARATOR); writer.write(Integer.toString(count.get(c).get())); } writer.newLine(); } } }
From source file:eu.itesla_project.eurostag.EurostagImpactAnalysis.java
private static void dumpBusesDictionary(Network network, EurostagDictionary dictionary, Path dir) throws IOException { try (BufferedWriter os = Files.newBufferedWriter(dir.resolve("dict_buses.csv"), StandardCharsets.UTF_8)) { for (Bus bus : Identifiables.sort(network.getBusBreakerView().getBuses())) { os.write(bus.getId() + ";" + dictionary.getEsgId(bus.getId())); os.newLine();//from w ww .ja v a 2s . c o m } } }
From source file:edu.vt.vbi.patric.cache.DataLandingGenerator.java
public boolean createCacheFileGenomicFeatures(String filePath) { boolean isSuccess = false; JSONObject jsonData = new JSONObject(); JSONObject data;//from w w w .j av a 2 s . c om // from WP // data data = read(baseURL + "/tab/dlp-genomicfeatures-data/?req=passphrase"); if (data != null) { jsonData.put("data", data); } // popular genomes data = getPopularGenomesForGenomicFeature(); if (data != null) { jsonData.put("popularGenomes", data); } // tools data = read(baseURL + "/tab/dlp-genomicfeatures-tools/?req=passphrase"); if (data != null) { jsonData.put("tools", data); } // process data = read(baseURL + "/tab/dlp-genomicfeatures-process/?req=passphrase"); if (data != null) { jsonData.put("process", data); } // download data = read(baseURL + "/tab/dlp-genomicfeatures-download/?req=passphrase"); if (data != null) { jsonData.put("download", data); } // save jsonData to file try (PrintWriter jsonOut = new PrintWriter( Files.newBufferedWriter(FileSystems.getDefault().getPath(filePath), Charset.defaultCharset()));) { jsonData.writeJSONString(jsonOut); isSuccess = true; } catch (IOException e) { LOGGER.error(e.getMessage(), e); } return isSuccess; }
From source file:de.ncoder.studipsync.studip.jsoup.JsoupStudipAdapter.java
public void saveCookies() throws IOException { if (cookiesPath != null) { log.info("Save Cookies"); if (Files.exists(cookiesPath)) { Files.delete(cookiesPath); }/* www .j a v a2 s . c om*/ try (Writer w = Files.newBufferedWriter(cookiesPath, Charset.defaultCharset())) { w.write(JSONValue.toJSONString(con.request().cookies())); } } }
From source file:net.sourceforge.hunterj.javadocViewer.JavadocViewerServlet.java
/** * // w w w.java 2 s . c o m * @param options * @throws IOException */ private synchronized void writeJavadocHomeOpts(String options) throws IOException { try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(this.saveFilePathStr), Charset.defaultCharset())) { writer.write(options); writer.close(); } }
From source file:com.github.ferstl.depgraph.AbstractGraphMojo.java
private void writeDotFile(String dotGraph) throws IOException { Path outputFilePath = this.outputFile.toPath(); Path parent = outputFilePath.getParent(); if (parent != null) { Files.createDirectories(parent); }/*from w w w . j a v a 2s . c o m*/ try (Writer writer = Files.newBufferedWriter(outputFilePath, StandardCharsets.UTF_8)) { writer.write(dotGraph); } }
From source file:edu.vt.vbi.patric.cache.DataLandingGenerator.java
public boolean createCacheFileSpecialtyGenes(String filePath) { boolean isSuccess = false; JSONObject jsonData = new JSONObject(); JSONObject data;/* w w w.ja v a2 s . c om*/ // from WP // data data = read(baseURL + "/tab/dlp-specialtygenes-data/?req=passphrase"); if (data != null) { jsonData.put("data", data); } // popular genomes data = getPopularGenomesForSpecialtyGene(); if (data != null) { jsonData.put("popularGenomes", data); } // tools data = read(baseURL + "/tab/dlp-specialtygenes-tools/?req=passphrase"); if (data != null) { jsonData.put("tools", data); } // process data = read(baseURL + "/tab/dlp-specialtygenes-process/?req=passphrase"); if (data != null) { jsonData.put("process", data); } // download data = read(baseURL + "/tab/dlp-specialtygenes-download/?req=passphrase"); if (data != null) { jsonData.put("download", data); } // save jsonData to file try (PrintWriter jsonOut = new PrintWriter( Files.newBufferedWriter(FileSystems.getDefault().getPath(filePath), Charset.defaultCharset()));) { jsonData.writeJSONString(jsonOut); isSuccess = true; } catch (IOException e) { LOGGER.error(e.getMessage(), e); } return isSuccess; }
From source file:edu.mit.fss.examples.member.gui.CommSubsystemPanel.java
/** * Exports this panel's connectivity dataset. *///from w w w .j av a 2 s. co m private void exportDataset() { if (JFileChooser.APPROVE_OPTION == fileChooser.showSaveDialog(this)) { File f = fileChooser.getSelectedFile(); if (!f.exists() || JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, "Overwrite existing file " + f.getName() + "?", "File Exists", JOptionPane.YES_NO_OPTION)) { logger.info("Exporting dataset to file " + f.getPath() + "."); try { BufferedWriter bw = Files.newBufferedWriter(Paths.get(f.getPath()), Charset.defaultCharset()); StringBuilder b = new StringBuilder(); // synchronize on map for thread safety synchronized (connectSeriesMap) { for (Transmitter tx : connectSeriesMap.keySet()) { TimeSeries s = connectSeriesMap.get(tx); b.append(tx.getName()).append(" Connectivity\n").append("Time, Value\n"); for (int j = 0; j < s.getItemCount(); j++) { b.append(s.getTimePeriod(j).getStart().getTime()).append(", ").append(s.getValue(j)) .append("\n"); } } } bw.write(b.toString()); bw.close(); } catch (IOException e) { logger.error(e); } } } }
From source file:org.tallison.gramreaper.terms.DumpTerms.java
private void writeTopN(Path path, AbstractTokenTFDFPriorityQueue queue) throws IOException { if (Files.isRegularFile(path)) { System.err.println("File " + path.getFileName() + " already exists. Skipping."); return;/*from w w w . j a v a 2 s .c o m*/ } Files.createDirectories(path.getParent()); BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8); for (String t : config.startWords) { writer.write(t + "\n"); } StringBuilder sb = new StringBuilder(); for (TokenDFTF tp : queue.getArray()) { writer.write(getRow(sb, tp) + "\n"); } writer.flush(); writer.close(); }
From source file:eu.itesla_project.eurostag.EurostagImpactAnalysis.java
private static void writeLimits(Network network, EurostagDictionary dictionary, Domain domain, OutputStream os) throws IOException { GenericArchive archive = domain.getArchiveFactory().create(GenericArchive.class); try (FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive)) { Path rootDir = fileSystem.getPath("/"); // dump first current limits for each of the branches try (BufferedWriter writer = Files.newBufferedWriter(rootDir.resolve(CURRENT_LIMITS_CSV), StandardCharsets.UTF_8)) { for (Line l : network.getLines()) { dumpLimits(dictionary, writer, l); }// w ww . j av a2s. c om for (TwoWindingsTransformer twt : network.getTwoWindingsTransformers()) { dumpLimits(dictionary, writer, twt); } for (DanglingLine dl : network.getDanglingLines()) { dumpLimits(dictionary, writer, dl.getId(), dl.getCurrentLimits(), null, dl.getTerminal().getVoltageLevel().getNominalV(), dl.getTerminal().getVoltageLevel().getNominalV()); } } try (BufferedWriter writer = Files.newBufferedWriter(rootDir.resolve(VOLTAGE_LIMITS_CSV), StandardCharsets.UTF_8)) { for (Bus b : network.getBusBreakerView().getBuses()) { VoltageLevel vl = b.getVoltageLevel(); if (!Float.isNaN(vl.getLowVoltageLimit()) && !Float.isNaN(vl.getHighVoltageLimit())) { writer.write(dictionary.getEsgId(b.getId())); writer.write(";"); writer.write(Float.toString(vl.getLowVoltageLimit())); writer.write(";"); writer.write(Float.toString(vl.getHighVoltageLimit())); writer.write(";"); writer.write(Float.toString(vl.getNominalV())); writer.newLine(); } } } //dump lines dictionary, for WP43 integration dumpLinesDictionary(network, dictionary, rootDir); //dump buses dictionary, for WP43 integration dumpBusesDictionary(network, dictionary, rootDir); } archive.as(ZipExporter.class).exportTo(os); }