List of usage examples for java.io FileWriter append
@Override public Writer append(CharSequence csq) throws IOException
From source file:org.ect.reo.simulation.views.SimulationViewResults.java
private static void fillCalculatedResult(Statistic statistic, Table table, String categoryDescription) { try {/*www .j a va 2 s. c om*/ // Add the calculated results of this statistic to the result output file. FileWriter resultWriter = SimulationView.resultWriter; resultWriter.append(categoryDescription + "[" + statistic.getDescription() + "], "); table.setRedraw(false); // Add all calculated results to the table TableItem item = new TableItem(table, SWT.NONE); item.setText(0, "Mean"); double mean = statistic.getMean(); double result = mean; item.setText(1, formatNumber(result, statistic)); resultWriter.append(result + ", "); item = new TableItem(table, SWT.NONE); result = statistic.getMeanCount(); item.setText(new String[] { "Observations per batch", integerFormat.format(result) }); resultWriter.append(result + ", "); item = new TableItem(table, SWT.NONE); result = statistic.getSd(); item.setText(new String[] { "Standard deviation", decimalFormat.format(result) }); resultWriter.append(result + ", "); item = new TableItem(table, SWT.NONE); result = (mean == 0) ? Double.NaN : statistic.getSd() / mean; item.setText(new String[] { "Coefficient of variation", decimalFormat.format(result) }); resultWriter.append(result + ", "); item = new TableItem(table, SWT.NONE); item.setText(0, "Interval"); double lowBound = statistic.getMean() - statistic.getConfidence(); double highBound = statistic.getMean() + statistic.getConfidence(); item.setText(1, "[" + formatNumber(lowBound, statistic) + ", " + formatNumber(highBound, statistic) + "]"); resultWriter.append(lowBound + ", "); resultWriter.append(Double.toString(highBound) + '\n'); table.setRedraw(true); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.mskcc.cbio.oncokb.quest.VariantAnnotationXMLV2.java
/** * This is a hacky way to run VEP. We should switch to web service once that is ready. *//*from ww w. j av a 2 s.c om*/ private static void runVcf2Maf(String inputXml, Map<Alteration, String> mapAlterationXml, String diagnosis) throws IOException, DocumentException, InterruptedException { File tmpFile = File.createTempFile("temp-oncokb-input-", ".xml"); tmpFile.deleteOnExit(); String inputPath = tmpFile.getAbsolutePath(); String outputPath = inputPath.substring(0, inputPath.length() - 3) + "oncokb.xml"; FileWriter writer = new FileWriter(tmpFile); writer.append(inputXml); writer.close(); String vepMafXmlPl = System.getenv("VEP_MAF_XML_PL"); if (null == vepMafXmlPl) { throw new IOException("VEP_MAF_XML_PL was not defined"); } Process proc = Runtime.getRuntime().exec(new String[] { "perl", vepMafXmlPl, inputPath }); proc.waitFor(); InputStream stderr = proc.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); String line = null; System.out.println("<ERROR>"); while ((line = br.readLine()) != null) System.out.println(line); System.out.println("</ERROR>"); int exitVal = proc.waitFor(); System.out.println("Process exitValue: " + exitVal); SAXReader reader = new SAXReader(); Document document = reader.read(outputPath); List<Node> variantNodes = document.selectNodes("//document/sample/test/variant"); for (Node node : variantNodes) { String alterationXml = "<variant_type>small_nucleotide_variant</variant_type>\n" + node.selectSingleNode("genomic_locus").asXML() + node.selectSingleNode("allele").asXML(); String geneSymbol = node.selectSingleNode("allele/transcript/hgnc_symbol").getText(); GeneBo geneBo = ApplicationContextSingleton.getGeneBo(); Gene gene = geneBo.findGeneByHugoSymbol(geneSymbol); String proteinChange = node.selectSingleNode("allele/transcript/hgvs_p_short").getText(); Alteration alteration = new Alteration(); alteration.setAlterationType(AlterationType.MUTATION); alteration.setGene(gene); alteration.setName(proteinChange); AlterationUtils.annotateAlteration(alteration, proteinChange); mapAlterationXml.put(alteration, alterationXml); } }
From source file:loadTest.loadTestLib.LUtil.java
public static void writeCSVResult(LoadTestConfigModel model, long resTime) throws IOException { FileWriter writer = new FileWriter("loadTestResults.csv", true); writer.append(String.valueOf(model.getNodeCount())); writer.append(","); writer.append(String.valueOf(model.getFileCount())); writer.append(","); writer.append(String.valueOf(model.getFileSize())); writer.append(","); writer.append(String.valueOf(resTime)); writer.append("\n"); writer.flush();//www . j av a2 s . c o m writer.close(); }
From source file:raptor.chess.pgn.PgnUtils.java
/** * Prepends the game to the users game pgn file. *///w w w.j av a 2 s.co m public static void appendGameToFile(Game game) { if (Variant.isBughouse(game.getVariant())) { return; } if (game.getMoveList().getSize() == 0) { return; } String pgnFilePath = Raptor.getInstance().getPreferences().getString(PreferenceKeys.APP_PGN_FILE); if (StringUtils.isNotEmpty(pgnFilePath)) { // synchronized on PGN_APPEND_SYNCH so just one thread at a time // writes to the file. synchronized (PGN_APPEND_SYNCH) { if (game instanceof GameCursor) { game = ((GameCursor) game).getMasterGame(); } String whiteRating = game.getHeader(PgnHeader.WhiteElo); String blackRating = game.getHeader(PgnHeader.BlackElo); whiteRating = StringUtils.remove(whiteRating, 'E'); whiteRating = StringUtils.remove(whiteRating, 'P'); blackRating = StringUtils.remove(blackRating, 'E'); blackRating = StringUtils.remove(blackRating, 'P'); if (!NumberUtils.isDigits(whiteRating)) { game.removeHeader(PgnHeader.WhiteElo); } if (!NumberUtils.isDigits(blackRating)) { game.removeHeader(PgnHeader.BlackElo); } String pgn = game.toPgn(); File file = new File(pgnFilePath); FileWriter fileWriter = null; try { fileWriter = new FileWriter(file, true); fileWriter.append(pgn).append("\n\n"); fileWriter.flush(); } catch (IOException ioe) { LOG.error("Error saving game", ioe); } finally { try { if (fileWriter != null) { fileWriter.close(); } } catch (IOException ioe) { } } } } }
From source file:main.RankerOCR.java
/** * Write all the given text in a new line in a CSV file * <p>//from ww w. ja va 2 s . c om * @param f CSV file to write * @param c Separator charter * @param s Values to write */ private static void writeOutpuDocCsv(File f, char c, String[] s) { FileWriter w = null; try { w = new FileWriter(f, true); for (String txt : s) { w.append(txt + c); } w.append("\n\r"); } catch (IOException ex) { printFormated(ex.getLocalizedMessage()); System.exit(-34); } finally { try { w.close(); } catch (IOException ex) { printFormated(ex.getLocalizedMessage()); System.exit(-34); } } }
From source file:com.github.rvesse.airline.parser.aliases.TestAliases.java
public static void prepareConfig(File f, String... lines) throws IOException { FileWriter writer = new FileWriter(f); for (String line : lines) { writer.append(line); writer.append('\n'); }/*w w w. j ava2 s . c o m*/ writer.close(); }
From source file:protein_spectrum_diversity.Analyse.java
public static File mergePeptides(Collection<String> sequences, File rootFolder, String outputFolder, String accession) throws IOException { File outputFile = new File(outputFolder + File.separator + accession + "_merged.mgf"); FileWriter out = new FileWriter(outputFile, true); for (String aSequence : sequences) { File sequenceMGF = getMGFForPeptide(aSequence, rootFolder); if (sequenceMGF.exists() && !sequenceMGF.isDirectory()) { BufferedReader in = new BufferedReader(new FileReader(sequenceMGF)); String line = ""; while ((line = in.readLine()) != null) { out.append(line).append(System.lineSeparator()).flush(); }/*w w w. j a va 2s .c o m*/ } } out.flush(); return outputFile; }
From source file:scoap3withapi.Scoap3withAPI.java
public static void writeFilesScoap3(String publickey, String privatekey, String date, int jrec, int num_rec) { String responseXML = null;//from w w w . j av a 2 s . c o m HttpClient client = new HttpClient(); HttpMethod method = callAPISCOAP3(publickey, privatekey, date, jrec, num_rec); try { client.executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_OK) { responseXML = convertStreamToString(method.getResponseBodyAsStream()); FileWriter fw = new FileWriter("MARCXML_SCOAP3_from_" + startDate + "_to_" + todayDate + "/marcXML_scoap3_" + jrec + "_" + num_rec + ".xml"); fw.append(responseXML); fw.close(); } } catch (IOException e) { e.printStackTrace(); } finally { method.releaseConnection(); } }
From source file:com.abiquo.am.services.filesystem.TemplateFileSystem.java
/** * synch to avoid multiple changes on the package folder (before 'clearOVFStatusMarks'). * /*from ww w . ja v a 2s.c om*/ * @throws RepositoryException */ public static synchronized void createTemplateStatusMarks(final String enterpriseRepositoryPath, final String ovfId, final TemplateStatusEnumType status, final String errorMsg) { final String packagePath = getTemplatePath(enterpriseRepositoryPath, ovfId); clearTemplateStatusMarks(packagePath); File mark = null; boolean errorCreate = false; try { switch (status) { case DOWNLOAD: // after clean the prev. marks, nothing to do. break; case NOT_DOWNLOAD: // once the OVF envelope (.ovf) is deleted its NOT_FOUND break; case DOWNLOADING: mark = new File(packagePath + '/' + TEMPLATE_STATUS_DOWNLOADING_MARK); errorCreate = !mark.createNewFile(); break; case ERROR: mark = new File(packagePath + '/' + TEMPLATE_STATUS_ERROR_MARK); errorCreate = !mark.createNewFile(); if (!errorCreate) { FileWriter fileWriter = new FileWriter(mark); fileWriter.append(errorMsg); fileWriter.close(); } break; default: throw new AMException(AMError.TEMPLATE_UNKNOW_STATUS, status.name()); }// switch } catch (IOException ioe) { throw new AMException(AMError.TEMPLATE_CHANGE_STATUS, mark.getAbsoluteFile().getAbsolutePath()); } if (errorCreate) { throw new AMException(AMError.TEMPLATE_CHANGE_STATUS, mark.getAbsoluteFile().getAbsolutePath()); } }
From source file:com.gumtreescraper.scraper.GumtreeScraper.java
public static void writeToCsvFile(List<Gumtree> gumtreesNeedToWrite, String outputCsvFileName) { try {// w w w.j av a 2 s . c om boolean isAppend = true; FileWriter writer = new FileWriter(outputCsvFileName, isAppend); for (Gumtree gumtree : gumtreesNeedToWrite) { writer.append(gumtree.toString()).append("\n"); } writer.flush(); writer.close(); } catch (IOException ex) { Logger.getLogger(GumtreeScraper.class.getName()).log(Level.SEVERE, null, ex); } }