List of usage examples for java.io BufferedWriter append
public Writer append(CharSequence csq) throws IOException
From source file:org.rhq.plugins.apache.ModJKComponent.java
/** * Delegate method to install a simple mod_jk in an apache httpd * @param serverComponent The parents server component with the configuration * @param params Params we got passed from the GUI * @return The outcome of the operation// w ww. j av a2 s . c o m * @throws Exception see thrown exception for details; thrown exception summarizes error */ public static OperationResult installModJk(ApacheServerComponent serverComponent, Configuration params) throws Exception { StringBuilder builder = new StringBuilder(); boolean needWorkersProps = false; boolean needUriWorkers = false; // First see (what) if stuff is present File httpdConf = serverComponent.getHttpdConfFile(); String confPath = httpdConf.getAbsolutePath(); // If we can't update the file, then there is nothing left to do. if (!httpdConf.canWrite()) { throw new Exception("Httpd.conf is not writable at " + confPath); } HttpdConfParser cparser = new HttpdConfParser(); cparser.parse(confPath); // TODO back up original file try { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(httpdConf, true)); if (cparser.isModJkInstalled()) { builder.append("Mod_jk is already installed\n"); if (cparser.getWorkerPropertiesFile() != null) { builder.append("Found a worker.properties file at ") .append(cparser.getWorkerPropertiesFile()); builder.append("\n"); } else needWorkersProps = true; if (cparser.getUriWorkerLocation() != null) { builder.append("Found a urimap file at ").append(cparser.getUriWorkerLocation()); } else needUriWorkers = true; } else { builder.append("No mod_jk installed yet at ").append(confPath).append("\n"); writer.append("LoadModule jk_module modules/mod_jk.so"); // TODO obtain modules location writer.newLine(); builder.append(".. written a LoadModule line \n"); needWorkersProps = true; needUriWorkers = true; } if (needWorkersProps) { writer.append("JkWorkersFile ").append("conf/workers.properties"); writer.newLine(); builder.append(".. installed worker.properties"); } if (needUriWorkers) { writer.append("JkMountFile ").append("conf/uriworkermap"); writer.newLine(); builder.append(".. installed uriworkermap"); } } finally { if (writer != null) { // close automatically flushes! writer.close(); } } } catch (IOException e) { builder.append("Error when installing mod_jk: \n"); builder.append(e.fillInStackTrace()); throw new Exception(builder.toString()); } OperationResult result = new OperationResult(); Configuration complexResults = result.getComplexResults(); complexResults.put(new PropertySimple(OUTPUT_RESULT_PROP, builder.toString())); return result; }
From source file:edu.utah.bmi.ibiomes.lite.ExperimentIndex.java
/** * Add entry (experiment) to index/*w ww . j a v a2 s .c om*/ * @param experimentPath Path to experiment * @throws IOException */ public void addEntry(String experimentPath) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(this.file, true)); bw.append(new IndexEntry(experimentPath).toString() + "\n"); bw.close(); }
From source file:com.stimulus.archiva.domain.Settings.java
public void store(String intro, OutputStream out, String charset) throws IOException { BufferedWriter output = new BufferedWriter(new OutputStreamWriter(out, charset)); output.append(intro); for (Map.Entry<String, String> property : entrySet()) { output.append(property.getKey()); output.append(keyValueSeparator); output.append(property.getValue()); output.newLine();/*from w w w. j a v a 2 s.c o m*/ } output.close(); }
From source file:org.envirocar.tools.TrackToCSV.java
public InputStream convert(InputStream in) throws IOException { FeatureCollection fc = new ObjectMapper().readValue(in, FeatureCollection.class); List<String> properties = new ArrayList<String>(); for (Feature feature : fc.getFeatures()) { for (String key : feature.getProperties().getPhenomenons().keySet()) { if (!properties.contains(key)) { properties.add(key);/*from w w w. ja v a 2s.c o m*/ } } } List<String> spaceTimeProperties = new ArrayList<String>(); spaceTimeProperties.add("longitude"); spaceTimeProperties.add("latitude"); spaceTimeProperties.add("time"); ByteArrayOutputStream out = new ByteArrayOutputStream(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); bw.append(createCSVHeader(properties, spaceTimeProperties)); bw.newLine(); for (Feature feature : fc.getFeatures()) { for (int i = 0; i < properties.size(); i++) { String key = properties.get(i); Map<?, ?> value = (Map<?, ?>) feature.getProperties().getPhenomenons().get(key); bw.append(value != null ? value.get("value").toString() : Double.toString(Double.NaN)); bw.append(delimiter); } Point coord = (Point) feature.getGeometry(); bw.append(Double.toString(coord.getCoordinates().getLongitude())); bw.append(delimiter); bw.append(Double.toString(coord.getCoordinates().getLatitude())); bw.append(delimiter); bw.append(feature.getProperties().getTime()); bw.newLine(); } bw.flush(); bw.close(); return new ByteArrayInputStream(out.toByteArray()); }
From source file:org.jboss.windup.metadata.decoration.Interrogation.java
public void renderHtml(BufferedWriter bw, boolean oddRow) throws IOException { bw.append("<tr "); bw.append("class='" + (oddRow ? "rowodd" : "roweven") + "'"); bw.append(">"); if (this.result != null) { bw.append("<td><a href='" + getReportRelativePath() + "'>" + getTitle() + "</a></td>"); bw.append("<td>" + getSummary() + "</td>"); } else {// w ww .j a va 2 s . c o m // else do not put a link... just the title. bw.append("<td>" + getTitle() + "</td>"); bw.append("<td>" + getSummary() + "</td>"); } bw.append("</tr>"); }
From source file:org.richfaces.tests.metamer.ftest.extension.attributes.coverage.saver.FullReportResultsSaver.java
protected void write(BufferedWriter bw) throws IOException { try {//from w w w . j a va 2s.c o m int covered = 0, notCovered = 0; for (CoverageResult result : getResults()) { bw.append(result.getReport()); bw.newLine(); bw.flush(); covered += result.getCovered().size() + result.getIgnored().size(); notCovered += result.getNotCovered().size(); } Fraction f = Fraction.getFraction(covered, covered + notCovered); bw.append("==========================================================="); bw.newLine(); bw.append("total coverage: ").append(f.toString()).append(" (") .append(String.valueOf((int) (f.doubleValue() * 100))).append("%)"); bw.newLine(); bw.flush(); } finally { if (bw != null) { bw.close(); } } }
From source file:com.sciaps.utils.ImportExportSpectrumCSV.java
public void exportSpectrumFile(File saveFile, RawDataSpectrum spectrum) throws IOException { if (spectrum == null || saveFile == null) { logger_.warn("", "will not save spectrum csv file"); return;/*from w ww . j a v a 2 s. co m*/ } BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(saveFile))); try { bout.append("wavelength, intensity"); bout.newLine(); double[][] data = spectrum.getRawData(); for (int i = 0; i < data[0].length; i++) { bout.append(Double.toString(data[0][i])); bout.append(", "); bout.append(Double.toString(data[1][i])); bout.newLine(); } } finally { bout.close(); } logger_.info("saved spectrum csv file to " + saveFile.getAbsolutePath()); }
From source file:com.sciaps.utils.ImportExportSpectrumCSV.java
public void exportSpectrumFile(File saveFile, PiecewiseSpectrum spectrum) throws IOException { if (spectrum == null || saveFile == null) { logger_.warn("", "will not save spectrum csv file"); return;//from w ww.ja v a 2 s .c om } final UnivariateFunction intensity = spectrum.getIntensityFunction(); BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(saveFile))); try { bout.append("wavelength, intensity"); bout.newLine(); final DoubleRange range = spectrum.getValidRange(); for (double x = range.getMinimumDouble(); x <= range.getMaximumDouble(); x += 1.0 / EXPORT_SAMPLE_RATE) { double y = intensity.value(x); if (Double.isNaN(y)) { y = 0; } bout.append(Double.toString(x)); bout.append(", "); bout.append(Double.toString(y)); bout.newLine(); } } finally { bout.close(); } logger_.info("saved spectrum csv file to " + saveFile.getAbsolutePath()); }
From source file:edu.isi.pfindr.learn.util.PairsFileIO.java
public static void generatePairsFromTwoDifferentFilesWithNoClass(String inputFilePath1, String inputFilePath2, String outputFilePath) {/* w w w . j a v a 2 s . c om*/ List<String> phenotypeList1 = new ArrayList<String>(); List<String> phenotypeList2 = new ArrayList<String>(); try { //Reader paramReader = new InputStreamReader(getClass().getResourceAsStream("/com/test/services/LoadRunner/FireCollection/fire.txt")); //System.out.println(PairsFileIO.class.getClassLoader().getResource(inputFilePath1).getPath()); //System.out.println(PairsFileIO.class.getClassLoader().getResource(inputFilePath2).getPath()); //phenotypeList1 = FileUtils.readLines(new File (PairsFileIO.class.getClassLoader().getResource(inputFilePath1).getPath())); //phenotypeList2 = FileUtils.readLines(new File (PairsFileIO.class.getClassLoader().getResource(inputFilePath2).getPath())); phenotypeList1 = FileUtils.readLines(new File(inputFilePath1)); phenotypeList2 = FileUtils.readLines(new File(inputFilePath2)); } catch (IOException ioe) { ioe.printStackTrace(); } String[] phenotype1, phenotype2; StringBuffer outputBuffer = new StringBuffer(); BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(outputFilePath)); for (int i = 0; i < phenotypeList1.size(); i++) { phenotype1 = phenotypeList1.get(i).split("\t"); for (int j = 0; j < phenotypeList2.size(); j++) { phenotype2 = phenotypeList2.get(j).split("\t"); //System.out.println("The value is:"+ phenotype1[3] + " : " + phenotype2[3]); outputBuffer.append(String.format("%s\t%s\t%d\n", phenotype1[3], phenotype2[3], 0)); bw.append(outputBuffer.toString()); outputBuffer.setLength(0); } } } catch (IOException io) { try { if (bw != null) { bw.close(); bw = null; } io.printStackTrace(); } catch (IOException e) { System.out.println("Problem occured while closing output stream " + bw); e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (bw != null) { bw.close(); bw = null; } } catch (IOException e) { System.out.println("Problem occured while closing output stream " + bw); e.printStackTrace(); } } }
From source file:org.kalypso.wspwin.core.WspWinProfProj.java
public void write(final File wspwinDir, final WspWinZustand[] zustaende) throws IOException { final WspWinProject wspwinProject = new WspWinProject(wspwinDir); final File profprojFile = wspwinProject.getProfProjFile(); final Collection<Pair<String, String>> profileStateMapping = new ArrayList<>(); /* Map profile files to state files */ for (final WspWinZustand zustand : zustaende) { final String stateFilename = zustand.getBean().getFileName(); final ProfileBean[] profileBeans = zustand.getProfileBeans(); for (final ProfileBean profileBean : profileBeans) { final String prfFilename = profileBean.getFileName(); profileStateMapping.add(Pair.of(prfFilename, stateFilename)); }/*ww w. ja va2 s. c o m*/ } /* Write list of profiles */ final BufferedWriter pw = new BufferedWriter(new FileWriter(profprojFile)); pw.append(String.format("%d %d%n", m_profiles.size(), profileStateMapping.size())); //$NON-NLS-1$ for (final ProfileBean profile : m_profiles) pw.append(profile.formatProfprojLine()).append(SystemUtils.LINE_SEPARATOR); pw.append(SystemUtils.LINE_SEPARATOR); /* Write mapping from .prf to .str */ for (final Pair<String, String> entry : profileStateMapping) { final String prfFilename = entry.getKey(); final String stateFilename = entry.getValue(); pw.append(String.format("%s %s%n", prfFilename, stateFilename)); //$NON-NLS-1$ } pw.close(); }