List of usage examples for java.io BufferedWriter write
public void write(int c) throws IOException
From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkChartWriter.java
public static void writeChartDataToFile(String filename, JFreeChart chart) { filename += ".txt"; try {//from w ww.j a v a2 s . com BufferedWriter writer = IOUtils.getBufferedWriter(filename); try { /*read "try" as if (plot instanceof XYPlot)*/ XYPlot xy = chart.getXYPlot(); String yAxisLabel = xy.getRangeAxis().getLabel(); String xAxisLabel = ""; if (xy.getDomainAxis() != null) { xAxisLabel = xy.getDomainAxis().getLabel(); } String header = xAxisLabel + "\t " + yAxisLabel; writer.write(header); writer.newLine(); for (int i = 0; i < xy.getDatasetCount(); i++) { XYDataset xyds = xy.getDataset(i); for (int seriesIndex = 0; seriesIndex < xyds.getSeriesCount(); seriesIndex++) { writer.newLine(); writer.write("Series " + "'" + xyds.getSeriesKey(seriesIndex).toString()); writer.write("'"); writer.newLine(); int items = xyds.getItemCount(seriesIndex); for (int itemsIndex = 0; itemsIndex < items; itemsIndex++) { Number xValue = xyds.getX(seriesIndex, itemsIndex); Number yValue = xyds.getY(seriesIndex, itemsIndex); writer.write(xValue.toString()); writer.write("\t"); writer.write(yValue.toString()); writer.newLine(); } } } System.out.println("Table written to : " + filename + "\n" + "=================================================="); } catch (ClassCastException e) { //else instanceof CategoryPlot log.info("caught class cast exception, trying to write CategoryPlot"); CategoryPlot cp = chart.getCategoryPlot(); String header = "CategoryRowKey \t CategoryColumnKey \t CategoryRowIndex \t CategoryColumnIndex \t Value"; writer.write(header); writer.newLine(); for (int i = 0; i < cp.getDatasetCount(); i++) { CategoryDataset cpds = cp.getDataset(i); for (int rowIndex = 0; rowIndex < cpds.getRowCount(); rowIndex++) { for (int columnIndex = 0; columnIndex < cpds.getColumnCount(); columnIndex++) { Number value = cpds.getValue(rowIndex, columnIndex); writer.write(cpds.getRowKey(rowIndex).toString()); writer.write("\t"); writer.write(cpds.getColumnKey(columnIndex).toString()); writer.write("\t"); writer.write(Integer.toString(rowIndex)); writer.write("\t"); writer.write(Integer.toString(columnIndex)); writer.write("\t"); writer.write(value.toString()); writer.newLine(); } } } } writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.hp.test.framework.Reporting.Utlis.java
public static void replaceMainTable(Boolean onlyMainTable, File f) { String content = ""; String content1 = ""; String replace = ""; String imagePath = "../../../../../../../"; if (f.getName().contentEquals("index.html")) { imagePath = ""; }//w w w. j ava 2 s.c om if (f.getName().contentEquals("ConsolidatedPage.html")) { imagePath = "../"; } if (f.getName().contentEquals("index.html")) { imagePath = ""; } if (f.getName().contentEquals("CurrentRun.html")) { imagePath = "../../"; } replace = "<tr id=\"header\" >" + "\n"; replace = replace + "<td id=\"logo\"><img src=\"" + imagePath + "HTML_Design_Files/IMG/Framework_Logo.jpg\" alt=\"Logo\" height=\"70\" width=\"140\" /> <br/><i style=\"float:left;padding-left:20px;font-size:12px\">Reflections of Visionary Minds</i></td>"; replace = replace + " <td id=\"headertext\">"; replace = replace + "Intelligent Solutions Test Framework"; replace = replace + "<div style=\"padding-right:20px;float:right\"><img src=\"" + imagePath + "HTML_Design_Files/IMG/hp.png\" height=\"70\" width=\"140\" /> </i></div> </td>"; replace = replace + " </tr>"; try { BufferedReader in = new BufferedReader(new FileReader(f)); String str; Boolean found = false; boolean readingdone = false; while ((str = in.readLine()) != null) { content1 += str; if (!onlyMainTable) { if (str.contains("<td id=\"content\">")) { content1 += " <img src=\"HTML_Design_Files\\\\IMG\\reports.jpg\" alt=\"BackGround\" height=\"500\" width=\"500\" /> "; in.readLine(); continue; } } if (str.contains("<table id=\"mainTable\">")) { found = true; } if (found) { while ((str = in.readLine()) != null) { if (str.contains("</tr>")) { found = false; readingdone = true; content1 += replace; break; } } } } in.close(); BufferedWriter out = new BufferedWriter(new FileWriter(f)); out.write(content1); out.close(); } catch (IOException e) { } }
From source file:com.wavemaker.commons.util.IOUtils.java
public static void write(File f, String s) throws IOException { f.getParentFile().mkdirs();//from w w w .j av a2s. c o m BufferedWriter br = null; try { br = new BufferedWriter(new FileWriter(f)); br.write(s); } finally { closeSilently(br); } }
From source file:atg.tools.dynunit.test.util.FileUtil.java
public static void forceComponentScope(final File file, final String scope) throws IOException { final long oldLastModified = getConfigFileLastModified(file); if (oldLastModified < file.lastModified()) { final File tempFile = newTempFile(); BufferedWriter out = null; BufferedReader in = null; try {//from www. jav a 2 s. c o m out = new BufferedWriter(new FileWriter(tempFile)); in = new BufferedReader(new FileReader(file)); for (String line = in.readLine(); line != null; line = in.readLine()) { if (line.contains("$scope")) { out.write("$scope="); out.write(scope); } else { out.write(line); } out.newLine(); } FileUtils.copyFile(tempFile, file); setConfigFileLastModified(file); dirty = true; } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } } }
From source file:gamlss.utilities.MatrixFunctions.java
/** * Write matrix values to CSV file./*from w w w . java 2s . c om*/ * @param cmd - path to the file * @param m - matrix to write */ public static void matrixWriteCSV(final String cmd, final BlockRealMatrix m) { try { // Create file FileWriter fstream = new FileWriter(cmd, false); BufferedWriter out = new BufferedWriter(fstream); for (int i = 0; i < m.getRowDimension(); i++) { for (int j = 0; j < m.getColumnDimension(); j++) { out.write(Double.toString(m.getEntry(i, j))); if (j < m.getColumnDimension() - 1) { out.append(','); } } out.newLine(); } out.close(); } catch (Exception e) { //Catch exception if any System.err.println("Error: " + e.getMessage()); } }
From source file:cn.org.citycloud.srdz.utils.FileUtils.java
/** * /*from ww w .j a v a 2s. c o m*/ * @param content * @param filePath */ public static void writeFile(String content, String filePath) { try { if (FileUtils.createFile(filePath)) { FileWriter fileWriter = new FileWriter(filePath, true); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(content); bufferedWriter.close(); fileWriter.close(); } else { log.info("??"); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.trackplus.ddl.DataReader.java
private static void writeInfoToFile(Map<String, String> info, String fileName) throws DDLException { BufferedWriter writer = createBufferedWriter(fileName); Iterator<String> it = info.keySet().iterator(); while (it.hasNext()) { String key = it.next();/*from www . j ava2 s .c o m*/ String value = info.get(key); try { writer.write(key); writer.write("="); writer.write(value); writer.newLine(); } catch (IOException ex) { throw new DDLException(ex.getMessage(), ex); } } try { writer.flush(); writer.close(); } catch (IOException e) { LOGGER.error("Error on close stream file " + fileName + " :" + e.getMessage()); throw new DDLException(e.getMessage(), e); } }
From source file:edu.caltech.ipac.firefly.server.query.IpacTablePartProcessor.java
protected static void writeLine(BufferedWriter writer, String text) throws IOException { writer.write(text); writer.newLine();//w ww . jav a2 s. c o m }
From source file:com.wavemaker.common.util.IOUtils.java
public static void write(File f, String s) throws IOException { f.getParentFile().mkdirs();/*from ww w .j a va 2 s. c o m*/ BufferedWriter br = null; try { br = new BufferedWriter(new FileWriter(f)); br.write(s); } finally { try { br.close(); } catch (Exception ignore) { } } }
From source file:URLEncoder.java
public static String encode(String s, String enc) throws UnsupportedEncodingException { if (!needsEncoding(s)) { return s; }/*from w w w . j av a 2s . c om*/ int length = s.length(); StringBuffer out = new StringBuffer(length); ByteArrayOutputStream buf = new ByteArrayOutputStream(10); // why 10? // w3c says // so. BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(buf, enc)); for (int i = 0; i < length; i++) { int c = (int) s.charAt(i); if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == ' ') { if (c == ' ') { c = '+'; } toHex(out, buf.toByteArray()); buf.reset(); out.append((char) c); } else { try { writer.write(c); if (c >= 0xD800 && c <= 0xDBFF && i < length - 1) { int d = (int) s.charAt(i + 1); if (d >= 0xDC00 && d <= 0xDFFF) { writer.write(d); i++; } } writer.flush(); } catch (IOException ex) { throw new IllegalArgumentException(s); } } } try { writer.close(); } catch (IOException ioe) { // Ignore exceptions on close. } toHex(out, buf.toByteArray()); return out.toString(); }