List of usage examples for java.io BufferedWriter write
public void write(int c) throws IOException
From source file:atg.tools.dynunit.util.ComponentUtil.java
private static void writeComponentPropertiesToFile(final File output, final String canonicalClassName, final Properties properties) throws IOException { logger.entry(output, canonicalClassName, properties); BufferedWriter out = null; try {//w ww . ja va 2 s . c o m out = new BufferedWriter(new FileWriter(output)); if (StringUtils.isNotEmpty(canonicalClassName)) { out.write("$class="); out.write(canonicalClassName); out.newLine(); } properties.store(out, canonicalClassName); } finally { if (out != null) { out.close(); } logger.exit(); } }
From source file:com.valco.utility.FacturasUtility.java
public static void guardaXml(String name, String content, String path, Integer facturaId) throws Exception { try {//from www . ja v a 2 s . c o m File file = new File(path + name); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); } catch (Exception ex) { throw new Exception("Factura " + facturaId + ": Ocurrio un error al generar el PDF."); } }
From source file:com.xtructure.xevolution.tool.impl.ReadPopulationsTool.java
private static void writeLatest(long latest) { try {/*from w w w . j a va 2 s .c om*/ BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(LATEST, false)); out.write(Long.toString(latest)); } finally { if (out != null) { out.close(); } } } catch (IOException e) { // nothing } }
From source file:com.doculibre.constellio.services.ImportExportServicesImpl.java
private static String convertText(String string) { // here, the conversion takes place automatically, // thanks to Java StringReader reader = new StringReader(string); StringWriter writer = new StringWriter(); try {/*from w ww . j a v a2s. c o m*/ BufferedReader bufferedreader = new BufferedReader(reader); BufferedWriter bufferedwriter = new BufferedWriter(writer); String line; while ((line = bufferedreader.readLine()) != null) { bufferedwriter.write(line); bufferedwriter.newLine(); } bufferedreader.close(); bufferedwriter.close(); } catch (IOException e) {/* HANDLE EXCEPTION */ } return writer.toString(); }
From source file:jeplus.INSELWinTools.java
/** * Call INSEL executable file to run the simulation * @param config INSEL Configuration/*from w w w. j a v a2s . c o m*/ * @param WorkDir The working directory where the input files are stored and the output files to be generated * @param useReadVars Whether or not to use readvars after simulation * @return the result code represents the state of execution steps. >=0 means successful */ public static int runINSEL(INSELConfig config, String WorkDir, String modelfile) { int ExitValue = -99; try { // Trace simulation time Date start = new Date(); // Run EnergyPlus executable String CmdLine = config.getResolvedInselEXEC() + " " + modelfile; Process EPProc = Runtime.getRuntime().exec(CmdLine, null, new File(WorkDir)); BufferedReader ins = new BufferedReader(new InputStreamReader(EPProc.getInputStream())); // Use console output as the report file BufferedWriter outs = new BufferedWriter(new FileWriter(WorkDir + config.ScreenFile, false)); outs.newLine(); outs.write("Calling insel.exe - " + (new SimpleDateFormat()).format(start)); outs.newLine(); outs.write("Command line: " + WorkDir + ">" + CmdLine); outs.newLine(); int res = ins.read(); while (res != -1) { outs.write(res); res = ins.read(); } ins.close(); outs.newLine(); outs.write("Simulation time: " + Long.toString((new Date().getTime() - start.getTime()) / 1000) + " seconds"); outs.flush(); outs.close(); EPProc.waitFor(); ExitValue = EPProc.exitValue(); } catch (IOException | InterruptedException e) { logger.error("Exception during INSEL execution.", e); } // Return Radiance exit value return ExitValue; }
From source file:ac.ucy.cs.spdx.license.License.java
/** * Saves the License passed as parameter in a text file inside the standard * directory.//from w w w. j a v a2 s .c o m * * @param License */ public static void saveLicense(License l) { File text = new File("licensesText/" + l.getIdentifier() + ".txt"); if (text.exists()) return; FileWriter fw = null; BufferedWriter bw = null; try { text.createNewFile(); fw = new FileWriter(text); bw = new BufferedWriter(fw); bw.write(l.getLicenseName() + "\n"); bw.write(l.getIdentifier() + "\n"); bw.write(l.getLicenseText()); } catch (IOException e) { e.printStackTrace(); } finally { try { bw.close(); fw.close(); } catch (IOException e) { } } }
From source file:com.hp.test.framework.htmparse.GenerateFailReport.java
public static void genarateFailureReport(File SourceFile, String TargetPath) { try {// w w w .j a va 2 s .co m Map<String, Map<String, List<String>>> Suites_list = new HashMap<>(); for (String key : UpdateTestCaseDesciption.TestCaseDesMap.keySet()) { Map<String, List<String>> test_status_list = new HashMap<>(); String status = UpdateTestCaseDesciption.TestcaseStatusMap.get(key); String[] temp_ar = key.split("\\\\"); List<String> Des = new ArrayList<String>(); Des.add(UpdateTestCaseDesciption.TestCaseDesMap.get(key)); Des.add(status); test_status_list.put(key, Des); if (!Suites_list.containsKey(temp_ar[0])) { Suites_list.put(temp_ar[0], test_status_list); } else { Map<String, List<String>> temp_status_list = Suites_list.get(temp_ar[0]); temp_status_list.put(key, Des); Suites_list.put(temp_ar[0], temp_status_list); } } String[] filename = SourceFile.getName().split("/."); BufferedReader in = new BufferedReader(new FileReader(SourceFile)); BufferedWriter out = new BufferedWriter(new FileWriter(TargetPath + "\\" + filename[0])); String str; while ((str = in.readLine()) != null) { if (str.contains("All Suites")) { out.write(str); for (String key : Suites_list.keySet()) { String Filter = "<option class=\"filterOption\"" + " value=\"" + key + "\">" + key + "</option>"; out.write(Filter); out.write("\n"); } continue; } if (str.contains("#suiteFilter")) { out.write(str); for (String key : Suites_list.keySet()) { String suiteFilter = "if($(this).val()=='" + key + "'){ $('.all').hide();$('." + key + "').show(); }"; out.write(suiteFilter); out.write("\n"); } continue; } out.write(str); } in.close(); int i = 1; for (String key : Suites_list.keySet()) { Map<String, List<String>> temp_status_list = Suites_list.get(key); for (String TestCase : temp_status_list.keySet()) { List<String> temp_list = temp_status_list.get(TestCase); // String[] temp_ar=temp.split("^"); String status = temp_list.get(1); String classTag = status + " all " + key; out.write("<tr class=\"" + classTag + "\">"); out.write("\n"); out.write("<td>" + String.valueOf(i) + "</td>"); out.write("\n"); out.write("\n"); out.write("<td>" + key + "</td>"); out.write("\n"); out.write("<td><font color=\"#013ADF\" size=\"3\">" + temp_list.get(0) + "</font></td>"); out.write("\n"); if (status.contains("fail")) { out.write( "<td style=\"font-weight:bold;vertical-align:middle;white-space:nowrap;font size=\"35;\"\"><font size=\"3\" color=\"Red\">" + "Fail" + "</font></td>"); } if (status.contains("pass")) { out.write( "<td style=\"font-weight:bold;vertical-align:middle;white-space:nowrap;font size=\"35;\"\"><font color=\"Green\">" + "Pass" + "</font></td>"); } if (status.contains("skip")) { out.write( "<td style=\"font-weight:bold;vertical-align:middle;white-space:nowrap;font size=\"35;\"\"><font color=\"Blue\">" + "Skip" + "</font></td>"); } out.write("\n"); out.write("</tr>"); out.write("\n"); i = i + 1; } } out.write("</Table>"); out.write("</body>"); out.write("</html>"); out.close(); System.out.println("Genarating Failure Report is Completed "); } catch (IOException e) { System.out.println("Exception in Replacing Counts in .js file is done " + e.getMessage()); } }
From source file:com.github.jsonj.tools.JsonSerializer.java
private static void newline(final BufferedWriter bw, final int n, final boolean pretty) throws IOException { if (pretty) { bw.write('\n'); for (int i = 0; i < n; i++) { bw.write('\t'); }//w ww .j a v a 2 s. c om } }
From source file:com.orange.atk.results.logger.documentGenerator.GraphGenerator.java
/** * Generate a graph in png from the provided plot list. The X axis of the * graph is in minutes./*from ww w .ja va 2s .c o m*/ * * @param plotList * plotlist to save. Xvalues must be stored in milliseconds. * @param associatedName * kind of the list * @param folderWhereResultsAreSaved * folder where graph while be saved * @param yLabel * name of the y label * @param pictureFile * name of the file where the picture would be saved (path should * be absolute) * @param yDivisor divisor of the measurements */ public static void generateGraph(PlotList plotList, String associatedName, String folderWhereResultsAreSaved, String yLabel, String pictureFile, float yDivisor) { Logger.getLogger("generateGraph").debug(folderWhereResultsAreSaved + associatedName + ".cmd"); // Store measurements in a file try { dumpInFile(plotList, folderWhereResultsAreSaved + associatedName + ".csv"); // Create gnuplot scripts used to generate graphs if (plotList.isEmpty()) { Logger.getLogger(GraphGenerator.class).warn(associatedName + " plot list is empty"); return; } // create a .cmd which will be given to the gnuplot program File commandFile = new File(folderWhereResultsAreSaved + associatedName + ".cmd"); BufferedWriter bufferedWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(commandFile))); // Picture will be saved in png bufferedWriter.write("set terminal png" + Platform.LINE_SEP); // Name of the picture bufferedWriter.write( "set output '" + folderWhereResultsAreSaved + associatedName + ".png'" + Platform.LINE_SEP); // format of the number on the y-axis bufferedWriter.write("set format y \"%.3s\"" + Platform.LINE_SEP); // Names of the axis bufferedWriter.write("set xlabel \"Time\"" + Platform.LINE_SEP); bufferedWriter.write("set ylabel \"" + yLabel + "\"" + Platform.LINE_SEP); // Set the range on y axis bufferedWriter.write("set yrange [" + (plotList.getMin() / yDivisor) * 0.9998 + ":" + (plotList.getMax() / yDivisor) * 1.0002 + "]" + Platform.LINE_SEP); bufferedWriter.write("set xtics autofreq" + Platform.LINE_SEP); bufferedWriter.write("set ytics autofreq" + Platform.LINE_SEP); bufferedWriter.write("plot '" + folderWhereResultsAreSaved + associatedName + ".csv' with lines" + Platform.LINE_SEP); bufferedWriter.flush(); bufferedWriter.close(); // call gnuplot for generating graphs Runtime runtime = Runtime.getRuntime(); String gnuplotName = null; if (Platform.OS_NAME.toLowerCase().contains("windows")) { gnuplotName = "wgnuplot"; } else { gnuplotName = "gnuplot"; } String[] cmdsCpu1 = { gnuplotName, folderWhereResultsAreSaved + associatedName + ".cmd" }; if (!plotList.isEmpty()) { // Call gnuplot int returnValue = runtime.exec(cmdsCpu1).waitFor(); if (returnValue != 0) { Logger.getLogger(GraphGenerator.class).warn( "Problem while creating graph. Does " + gnuplotName + " program belongs to PATH?"); } } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.k_joseph.apps.multisearch.solr.AddCustomFieldsToSchema.java
/** * Reads the schema file line by line and edits it to add a new field entry * /* ww w . j a va 2s . c o m*/ * @param schemaFileLocation * @param fieldEntry, the field entry line, use * {@link #generateAWellWrittenFieldEntry(String, String, boolean, boolean, boolean)} * @return new lines of the file in a List */ public static void readSchemaFileLineByLineAndWritNewFieldEntries(String schemaFileLocation, String newSchemaFilePath, String fieldEntry, String copyFieldEntry, SolrServer solrServer) { //reading file line by line in Java using BufferedReader FileInputStream fis = null; BufferedReader reader = null; boolean replacedSchemaWithBackUp = replaceSchemaFileWithItsBackup(schemaFileLocation); if (replacedSchemaWithBackUp) { System.out.println("Successfully replaced the schema.xml file with a previously backed-up copy"); } try { fis = new FileInputStream(schemaFileLocation); reader = new BufferedReader(new InputStreamReader(fis)); System.out.println("Reading " + schemaFileLocation + " file line by line using BufferedReader"); File newSchemaFile = new File(newSchemaFilePath); if (newSchemaFile.exists()) newSchemaFile.delete(); String line = reader.readLine(); while (line != null) { FileWriter fileWritter = new FileWriter(newSchemaFile, true); BufferedWriter bufferWritter = new BufferedWriter(fileWritter); //write to the file from here. if (line.equals("\t\t<!-- Fields from modules and other projects starts here -->")) { bufferWritter.write("\t\t<!-- Fields from modules and other projects starts here -->\n" + fieldEntry + "\n"); bufferWritter.close(); } else if (line.equals("\t<!-- Starting customly added copyfields -->")) { bufferWritter .write("\n\t<!-- Starting customly added copyfields -->\n" + copyFieldEntry + "\n"); bufferWritter.close(); } else { bufferWritter.write(line + "\n"); bufferWritter.close(); } line = reader.readLine(); } } catch (FileNotFoundException ex) { Logger.getLogger(AddCustomFieldsToSchema.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(AddCustomFieldsToSchema.class.getName()).log(Level.SEVERE, null, ex); } finally { try { reader.close(); fis.close(); } catch (IOException ex) { Logger.getLogger(AddCustomFieldsToSchema.class.getName()).log(Level.SEVERE, null, ex); } } copyNewSchemaFileToPreviouslyUsed(schemaFileLocation, newSchemaFilePath); CoreAdminRequest adminRequest = new CoreAdminRequest(); reloadSolrServer(solrServer, adminRequest); }