List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:edu.caltech.ipac.firefly.server.query.IpacTablePartProcessor.java
protected static void writeLine(BufferedWriter writer, String text) throws IOException { writer.write(text);//from w w w .ja va2 s . c om writer.newLine(); }
From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkChartWriter.java
public static void writeChartDataToFile(String filename, JFreeChart chart) { filename += ".txt"; try {/*w w w . j a va 2s. c o m*/ 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:de.unibi.techfak.bibiserv.util.codegen.Main.java
/** * Copy a text based file from in to out and replace TEMPLATE_ID with 'id' * and TEMPLATE_NAME with 'name'/*from w ww . ja v a 2 s .c o m*/ * * * @param in * @param out * @param id * @param name * @throws IOException */ public static void CopyAndReplace(InputStream in, OutputStream out, String id, String name, String version) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); String line; while ((line = br.readLine()) != null) { bw.append(line.replace("TEMPLATE_ID", id).replace("TEMPLATE_NAME", name).replace("TEMPLATE_VERSION", version)); bw.newLine(); } br.close(); bw.close(); }
From source file:playground.dgrether.analysis.charts.utils.DgChartWriter.java
public static void writeChartDataToFile(String filename, JFreeChart chart) { filename += ".txt"; try {//from w ww.j av a 2 s .co m 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(); //write the header writer.write("#"); for (int i = 0; i < xy.getDatasetCount(); i++) { XYDataset xyds = xy.getDataset(i); int seriesIndex = 0; int maxItems = 0; int seriesCount = xyds.getSeriesCount(); while (seriesIndex < seriesCount) { writer.write("Series " + xyds.getSeriesKey(seriesIndex).toString()); if (seriesIndex < seriesCount - 1) { writer.write("\t \t"); } if (xyds.getItemCount(seriesIndex) > maxItems) { maxItems = xyds.getItemCount(seriesIndex); } seriesIndex++; } writer.newLine(); //write the data Number xValue, yValue = null; for (int itemsIndex = 0; itemsIndex < maxItems; itemsIndex++) { for (int seriesIdx = 0; seriesIdx < seriesCount; seriesIdx++) { if (seriesIdx < xyds.getSeriesCount() && itemsIndex < xyds.getItemCount(seriesIdx)) { xValue = xyds.getX(seriesIdx, itemsIndex); yValue = xyds.getY(seriesIdx, itemsIndex); if (xValue != null && yValue != null) { writer.write(xValue.toString()); writer.write("\t"); writer.write(yValue.toString()); if (seriesIdx < seriesCount - 1) { writer.write("\t"); } } } } writer.newLine(); } } } catch (ClassCastException e) { //else instanceof CategoryPlot log.info("Due to a caught class cast exception, it should be a 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(); log.info("Chart data written to: " + filename); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void visitRecursively(Node node, BufferedWriter bw) throws Exception { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { // get child node Node childNode = list.item(i); if (childNode.getNodeType() == Node.TEXT_NODE) { System.out.println("Found Node: " + childNode.getNodeName() + " - with value: " + childNode.getNodeValue() + " Node type:" + childNode.getNodeType()); String nodeValue = childNode.getNodeValue(); nodeValue = nodeValue.replace("\n", "").replaceAll("\\s", ""); if (!nodeValue.isEmpty()) { System.out.println(nodeValue); bw.write(nodeValue);/*from w w w . j a v a2s . c o m*/ bw.newLine(); } } visitRecursively(childNode, bw); } }
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();// www . ja v a2 s.co 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.umn.cs.spatialHadoop.util.FileUtil.java
/** * Writes paths to a file where each path is a line. * /*from w w w . ja v a2 s.com*/ * @author ibrahimsabek * @param paths */ public static Path writePathsToFile(OperationsParams params, Path[] paths) { String tmpFileName = "pathsDictionary.txt"; File tempFile; BufferedWriter buffWriter = null; try { // store the dictionary of paths in a local file tempFile = new File(tmpFileName); Path localFilePath = new Path(tempFile.getAbsolutePath()); FileOutputStream outStream = new FileOutputStream(tempFile); buffWriter = new BufferedWriter(new OutputStreamWriter(outStream)); for (int i = 0; i < paths.length; i++) { buffWriter.write(paths[i].toString()); buffWriter.newLine(); } // copy the local dictionary into an hdfs file Configuration conf = new Configuration(); FileSystem fs = params.getPaths()[0].getFileSystem(conf); Path hdfsFilePath = new Path(params.getPaths()[0].toString() + "/" + tmpFileName); copyFromLocal(localFilePath, fs, hdfsFilePath); return hdfsFilePath; } catch (IOException e) { e.printStackTrace(); return null; } finally { IOUtils.closeQuietly(buffWriter); } }
From source file:DataBase.DatabaseManager.java
public static void writeKeywordsToFile(ArrayList<Book> books) { LOG.info("Keywords are writting to a file..."); try {/*from w ww . j a v a 2 s. c om*/ BufferedWriter out = new BufferedWriter(new FileWriter("file/keywords_output.txt", false)); for (Book book : books) { for (int i = 0; i < book.getKeywords().size(); i++) { String line = book.getKeywords().get(i).getKeyword_id() + ";" + book.getKeywords().get(i).getName(); out.write(line); out.newLine(); } } out.close(); } catch (IOException e) { } LOG.info("Writting is done..."); }
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 w ww .j a v a2 s. com*/ 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:net.openchrom.xxd.processor.supplier.rscripting.ui.code.RServe.java
/** * Evaluates and prints an expression to the Plugin console executed in a job. * // w w w . j a va 2 s . c o m * @param expression * a R expression as a string. */ public static void printJob(String expression) {// helper class to print if (RState.isBusy() == false) { RState.setBusy(true); REvaluateJob job = new REvaluateJob(expression); job.addJobChangeListener(new JobChangeAdapter() { public void done(IJobChangeEvent event) { if (event.getResult().isOK()) { int countDev = getDisplayNumber(); RState.setBusy(false); if (countDev > 0) { RServe.closeAndDisplay(); } System.out.flush(); } else { RState.setBusy(false); System.out.flush(); } } }); // job.setSystem(true); job.schedule(); } else { Process p; IPreferenceStore store = Activator.getDefault().getPreferenceStore(); if (store.getBoolean("RSERVE_NATIVE_START")) { ConsolePageParticipant consol = ConsolePageParticipant.getConsolePageParticipantInstance(); p = consol.getRProcess(); } else { p = RConnectionJob.getProc(); } // Write to the output! if (p != null) { final OutputStream os = p.getOutputStream(); final OutputStreamWriter osw = new OutputStreamWriter(os); final BufferedWriter bw = new BufferedWriter(osw, 100); try { bw.write(expression); bw.newLine(); os.flush(); bw.flush(); // bw.close(); System.out.flush(); } catch (IOException e) { System.err.println(""); } } MsgDialog.message("Rserve is busy!"); } }