List of usage examples for java.io BufferedWriter BufferedWriter
public BufferedWriter(Writer out)
From source file:com.incapture.rapgen.output.OutputWriter.java
/** * Some files are composed of multiple templates. So the map passed in here is filename to template order to template. * E.g. "file.txt"->1->"some code" "file.txt"->2->"other code" and so on. * * @param rootFolder/*from w w w . j a va 2 s . c o m*/ * @param pathToTemplate */ public static void writeMultiPartTemplates(String rootFolder, Map<String, Map<String, StringTemplate>> pathToTemplate) { // For each file, dump the templates for (Map.Entry<String, Map<String, StringTemplate>> entry : pathToTemplate.entrySet()) { File file = new File(rootFolder, entry.getKey()); file.getParentFile().mkdirs(); BufferedWriter bow = null; try { bow = new BufferedWriter(new FileWriter(file)); Set<String> sections = entry.getValue().keySet(); SortedSet<String> sorted = new TreeSet<String>(); sorted.addAll(sections); for (String sec : sorted) { bow.write(entry.getValue().get(sec).toString()); bow.newLine(); } bow.close(); } catch (IOException e) { System.err.println(e.getMessage()); } finally { if (bow != null) { try { bow.close(); } catch (IOException e) { System.err.println("Error closing output stream: " + ExceptionToString.format(e)); } } } } }
From source file:CSVFileWriter.java
public CSVFileWriter(Writer writer) { this.writer = new BufferedWriter(writer); this.format = new CSVFormat(); }
From source file:de.highbyte_le.weberknecht.request.view.JsonActionProcessor.java
public boolean processView(HttpServletRequest request, HttpServletResponse response, JsonView action) throws IOException, JSONException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); BufferedWriter writer = null; try {//from w w w. j av a 2s . co m writer = new BufferedWriter(response.getWriter()); JSONWriter jsonWriter = new JSONWriter(writer); action.writeJson(jsonWriter); writer.flush(); } finally { if (writer != null) writer.close(); } return true; }
From source file:edu.iu.daal_kmeans.regroupallgather.KMUtil.java
/** * Generate centroids and upload to the cDir * //from www . j av a 2 s . c o m * @param numCentroids * @param vectorSize * @param configuration * @param random * @param cenDir * @param fs * @throws IOException */ static void generateCentroids(int numCentroids, int vectorSize, Configuration configuration, Path cenDir, FileSystem fs) throws IOException { Random random = new Random(); double[] data = null; if (fs.exists(cenDir)) fs.delete(cenDir, true); if (!fs.mkdirs(cenDir)) { throw new IOException("Mkdirs failed to create " + cenDir.toString()); } data = new double[numCentroids * vectorSize]; for (int i = 0; i < data.length; i++) { data[i] = random.nextDouble() * 1000; } Path initClustersFile = new Path(cenDir, Constants.CENTROID_FILE_NAME); System.out.println("Generate centroid data." + initClustersFile.toString()); FSDataOutputStream out = fs.create(initClustersFile, true); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); for (int i = 0; i < data.length; i++) { if ((i % vectorSize) == (vectorSize - 1)) { bw.write(data[i] + ""); bw.newLine(); } else { bw.write(data[i] + " "); } } bw.flush(); bw.close(); System.out.println("Wrote centroids data to file"); }
From source file:com.sat.common.CustomReport.java
/** * Generate html file.//from w ww . j ava2s . c om * * @param msg the msg * @throws IOException Signals that an I/O exception has occurred. * @throws FileNotFoundException the file not found exception */ private static void generateHtmlFile(String msg) throws IOException, FileNotFoundException { String htmlfname = "./customreport.html"; String eol = System.getProperty("line.separator"); msg = msg.replaceAll("<tr", eol + "<tr"); msg = msg.replaceAll("</table>", eol + "</table>"); msg = msg.replaceAll("<table", eol + "<table"); new FileOutputStream(htmlfname).close(); PrintWriter htmlfile = new PrintWriter(new BufferedWriter(new FileWriter(htmlfname, true))); htmlfile.print(msg); htmlfile.close(); }
From source file:finalproject.FileIO.java
/** * Prints the date, data, and the notes to a file for later use * @param date//from w w w . j a va 2 s. c o m * @param data * @param notes */ public void outputToFile(String date, String[][] data, String notes) { //File f = new File("Resources/Data/" + date + ".txt"); // For "commercial" use //File f = new File("C:\\Program Files\\BGDataAnalysis\\Data\\" + date + ".txt"); File f = new File("C:\\BGDataAnalysis\\Data\\" + date + ".txt"); try { BufferedWriter wrtr = new BufferedWriter(new FileWriter(f)); wrtr.write(date); wrtr.newLine(); wrtr.write(notes); wrtr.newLine(); for (int i = 0; i < 24; i++) { if (data[i][1] != null) { wrtr.write(data[i][0] + "%" + data[i][1]); wrtr.newLine(); } } wrtr.close(); } catch (Exception ex) { System.out.println("Output Error!"); System.out.println(ex.getMessage()); } }
From source file:com.github.seqware.queryengine.system.Utility.java
/** * Write to output file a tab separated key value file represented by map * * @param outputFile a {@link java.io.File} object. * @param map a {@link java.util.Map} object. *///from w w w . j a v a 2s . c o m public static void writeKeyValueFile(File outputFile, Map<String, String> map) { if (outputFile != null) { try { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile))); for (Map.Entry<String, String> e : map.entrySet()) { out.println(e.getKey() + "\t" + e.getValue()); Logger.getLogger(FeatureImporter.class.getName()) .info("Writing " + e.getKey() + " " + e.getValue() + " file"); } out.close(); } catch (IOException ex) { Logger.getLogger(FeatureImporter.class.getName()).fatal("Could not write to output file"); } } }
From source file:at.orz.arangodb.http.JsonSequenceEntity.java
public void writeTo(OutputStream outstream) throws IOException { if (outstream == null) { throw new IllegalArgumentException("Output stream may not be null"); }/*from w ww . j a v a 2 s. c om*/ BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(outstream, "UTF-8")); while (it.hasNext()) { Object value = it.next(); gson.toJson(value, writer); writer.newLine(); } writer.flush(); } finally { } }
From source file:com.interacciones.mxcashmarketdata.driver.process.impl.FileMessageProcessing.java
public FileMessageProcessing() { try {/*from w w w .j a v a2 s. c om*/ file = new File("ProcessingFilter.log"); is = new FileWriter(file, true); bf = new BufferedWriter(is); formato = new SimpleDateFormat("H:mm:ss.SSS"); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.dclab.preparation.ReadTest.java
public ReadTest(String path) throws IOException { bfw = new BufferedWriter(new FileWriter("grants.txt")); File folder = new File(path); dig(folder);//from w ww . j av a 2 s .c o m bfw.close(); }