List of usage examples for java.io BufferedWriter append
public Writer append(CharSequence csq) throws IOException
From source file:com.anton.gavel.ComplaintSubmission.java
public void appendLog(String text) { File logFile = new File("sdcard/log.txt"); if (logFile.exists()) logFile.delete();//from w w w.j a v a 2 s. com if (!logFile.exists()) { try { logFile.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { //BufferedWriter for performance, true to set append to file flag BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); buf.append(text); buf.newLine(); buf.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.gatein.wcm.util.FileAux.java
public static boolean changeLinksOnFile(File input, File output, Map<Long, Long> mUploads) { if (input == null || output == null || mUploads.size() == 0) return false; FileReader reader;// w ww. j av a2 s. c o m FileWriter writer; BufferedReader bReader; BufferedWriter bWriter; try { reader = new FileReader(input); writer = new FileWriter(output); bReader = new BufferedReader(reader); bWriter = new BufferedWriter(writer); } catch (FileNotFoundException e) { log.warning("File not found " + input + ". Msg: " + e.getMessage()); return false; } catch (IOException e) { log.warning("Error writing file " + output + ". Msg: " + e.getMessage()); return false; } boolean modified = false; try { String line; while ((line = bReader.readLine()) != null) { // Checking token String changed = changeLinks(line, mUploads); if (changed != null && changed.length() > 0) { line = changed; modified = true; } bWriter.append(line); bWriter.newLine(); } } catch (IOException e) { log.warning("Error reading or writing on " + input + " or " + output + ". Msg: " + e.getMessage()); } finally { try { bReader.close(); bWriter.close(); } catch (IOException ee) { // Silent on close } } return modified; }
From source file:com.zestedesavoir.zestwriter.model.Content.java
public void saveToMarkdown(File file) { DateFormat dateFormat = new SimpleDateFormat("dd MMMMM yyyy"); StringBuilder sb = new StringBuilder(); sb.append("% ").append(getTitle().toUpperCase()).append("\n"); sb.append("% ").append(dateFormat.format(new Date())).append("\n\n"); sb.append("# ").append(getIntroduction().getTitle()).append("\n\n"); try (FileOutputStream fos = new FileOutputStream(file)) { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF8")); writer.append(sb.toString()); writer.append(exportContentToMarkdown(0, getDepth())); writer.flush();// www .j av a 2s . c o m } catch (Exception e) { MainApp.getLogger().error(e.getMessage(), e); } }
From source file:com.uksf.mf.core.utility.sqm.SqmFixer.java
/** * Saves sqm using given List/*from w w w .j av a 2 s. com*/ * @param sqmOut List to save */ private void saveSqm(List<String> sqmOut) throws IOException { activeFile.delete(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(activeFile, true))); for (String line : sqmOut) { writer.append(line).append("\r\n"); } writer.close(); }
From source file:edu.utah.bmi.ibiomes.lite.ExperimentIndex.java
private void storeIndexToFile(HashMap<String, IndexEntry> index) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(this.file, false)); Collection<IndexEntry> entries = index.values(); for (IndexEntry entry : entries) { bw.append(entry.toString() + "\n"); }/*from w w w. j a va 2s. com*/ bw.close(); }
From source file:org.dkpro.tc.ml.liblinear.LiblinearTestTask.java
private void predict(TaskContext aContext, Model model, Problem test) throws Exception { File predFolder = aContext.getFolder("", AccessMode.READWRITE); String predFileName = LiblinearAdapter.getInstance() .getFrameworkFilename(AdapterNameEntries.predictionsFile); File predictionsFile = new File(predFolder, predFileName); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(predictionsFile), "utf-8")); writer.append("#PREDICTION;GOLD" + "\n"); Feature[][] testInstances = test.x;//from w w w. j a va2 s . co m for (int i = 0; i < testInstances.length; i++) { Feature[] instance = testInstances[i]; Double prediction = Linear.predict(model, instance); writer.write(prediction.intValue() + SEPARATOR_CHAR + new Double(test.y[i]).intValue()); writer.write("\n"); } writer.close(); }
From source file:de.clusteval.data.dataset.generator.CassiniDataSetGenerator.java
@Override protected GoldStandard generateGoldStandard() throws GoldStandardGenerationException { try {// ww w.j a v a2 s . c o m // goldstandard file File goldStandardFile = new File(FileUtils.buildPath(this.repository.getBasePath(GoldStandard.class), this.getFolderName(), this.getFileName())); BufferedWriter writer = new BufferedWriter(new FileWriter(goldStandardFile)); for (int row = 0; row < classes.length; row++) { writer.append((row + 1) + "\t" + classes[row] + ":1.0"); writer.newLine(); } writer.close(); return new GoldStandard(repository, goldStandardFile.lastModified(), goldStandardFile); } catch (IOException e) { e.printStackTrace(); } catch (RegisterException e) { e.printStackTrace(); } throw new GoldStandardGenerationException("The goldstandard could not be generated!"); }
From source file:org.matsim.contrib.drt.analysis.DrtRequestAnalyzer.java
public void writeAndPlotWaitTimeEstimateComparison(String plotFileName, String textFileName) { BufferedWriter bw = IOUtils.getBufferedWriter(textFileName); XYSeries times = new XYSeries("waittimes", true, true); try {/*from ww w. ja va2s.c o m*/ bw.append("RequestId;actualWaitTime;estimatedWaitTime;deviate"); for (Entry<Id<Request>, Tuple<Double, Double>> e : this.waitTimeCompare.entrySet()) { bw.newLine(); double first = e.getValue().getFirst(); double second = e.getValue().getSecond(); bw.append(e.getKey().toString() + ";" + first + ";" + second + ";" + (first - second)); times.add(first, second); } bw.flush(); bw.close(); final JFreeChart chart2 = DensityScatterPlots.createPlot("Wait times", "Actual wait time [s]", "Initially planned wait time [s]", times, Pair.of(0., drtCfg.getMaxWaitTime())); // xAxis.setLowerBound(0); // yAxis.setLowerBound(0); ChartUtilities.writeChartAsPNG(new FileOutputStream(plotFileName), chart2, 1500, 1500); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:nz.co.jsrsolutions.ds3.sink.CsvEodDataSink.java
public void updateExchangeSymbolQuotes(String exchange, String symbol, QUOTE[] quotes) throws EodDataSinkException { try {//from w ww . jav a 2s. c om StringBuffer filenameBuf = new StringBuffer(); filenameBuf.append("/data/eoddata/"); filenameBuf.append(exchange); filenameBuf.append("/"); filenameBuf.append(symbol); filenameBuf.append("/"); filenameBuf.append(exchange); filenameBuf.append("."); filenameBuf.append(symbol); // filenameBuf.append("."); // filenameBuf.append(startDate); // filenameBuf.append("-"); // filenameBuf.append(endDate); // filenameBuf.append("."); // filenameBuf.append(period); filenameBuf.append(".csv"); String filename = new String(filenameBuf.toString()); StringBuffer infoMessage = new StringBuffer(); infoMessage.append("Writing output to: [ "); infoMessage.append(filename); infoMessage.append(" ] "); logger.info(infoMessage.toString()); FileWriter fileWriter = new FileWriter(filenameBuf.toString()); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); for (DataStub.QUOTE quote : quotes) { Calendar calendar = quote.getDateTime(); bufferedWriter.append(Integer.toString(calendar.get(Calendar.YEAR))); bufferedWriter.append(String.format("%02d", calendar.get(Calendar.MONTH))); bufferedWriter.append(String.format("%02d", calendar.get(Calendar.DAY_OF_MONTH))); bufferedWriter.append(","); bufferedWriter.append(Double.toString(quote.getClose())); bufferedWriter.newLine(); } bufferedWriter.close(); } catch (java.io.IOException ioe) { logger.error(ioe.toString()); EodDataSinkException edpe = new EodDataSinkException("Unable to set symbols"); edpe.initCause(ioe); throw edpe; } }
From source file:org.ihtsdo.statistics.Processor.java
/** * Adds the header./*from w ww .j a v a2s .c o m*/ * * @param bw the bw * @param detail the detail * @throws IOException Signals that an I/O exception has occurred. */ private void addHeader(BufferedWriter bw, OutputDetailFile detail) throws IOException { bw.append(detail.getReportHeader()); bw.append("\r\n"); }