List of usage examples for java.io FileWriter append
@Override public Writer append(CharSequence csq) throws IOException
From source file:com.gnizr.web.action.export.ExportNetscapeBookmarks.java
private void writeBookmark(FileWriter fwriter, Bookmark bookmark) throws IOException { fwriter.append("<DT><A HREF=\""); fwriter.append(bookmark.getLink().getUrl()); fwriter.append("\""); if (bookmark.getTags().length() > 0) { fwriter.append(" TAGS=\""); fwriter.append(bookmark.getTags()); fwriter.append("\" "); }//from w ww . ja v a2 s . com fwriter.append(">"); StringEscapeUtils.escapeHtml(fwriter, bookmark.getTitle().trim()); fwriter.append("</A>"); if (bookmark.getNotes() != null && bookmark.getNotes().length() > 0) { fwriter.append("<DD>"); String notes = bookmark.getNotes(); notes = FormatUtil.tidyAndExtractTextFromHtml(notes); if (notes.length() > 255) { StringEscapeUtils.escapeHtml(fwriter, notes.substring(0, 255).trim()); fwriter.append(" [...]"); } else { StringEscapeUtils.escapeHtml(fwriter, notes.trim()); } } fwriter.append("</DD>\n"); }
From source file:framework.GroovyTemplateEngine.java
public void generate(String name, Reader reader, File outputFile) throws FileNotFoundException, IOException { List<String> imports = IOUtils.readLines(Template.class.getResourceAsStream("/imports.groovy")); FileWriter writer = new FileWriter(outputFile); try {// w ww .jav a 2 s . com for (String line : imports) { writer.append(line).append('\n'); } writer.append("framework.ThreadData data = framework.FrontController.threadData.get()\n"); writer.append("Writer out = data.out\n"); int s = 0; int ch = -1; writer.append("out.write '"); while ((ch = reader.read()) != -1) { if (ch == '<' && s == 0) { s = 1; writer.append("'\n"); } else if (ch == '%' && s == 1) { s = 2; } else if (ch == '#' && s == 2) { s = 7; } else if (s == 1) { s = 0; writer.append("out.write '<"); addChar(writer, s, ch); } else if (ch == '=' && s == 2) { s = 3; writer.append("out.write '' + ("); } else if (s == 2) { s = 6; addChar(writer, s, ch); } else if (ch == '%' && s == 7) { s = 8; } else if (ch == '%' && s == 6) { s = 4; } else if (ch == '%' && s == 3) { s = 5; } else if (ch == '>' && s == 8) { s = 0; writer.append("out.write '"); } else if (ch == '>' && s == 4) { s = 0; writer.append("\nout.write '"); } else if (ch == '>' && s == 5) { s = 0; writer.append(")\nout.write '"); } else if (s == 4) { s = 2; writer.append('%'); } else if (s == 5) { s = 3; writer.append('%'); } else if (ch == '\n') { if (s == 0) { writer.append("\\n'\nout.write '"); } else { writer.append(" "); } s = 0; } else if (ch == '\r') { if (s != 0) { writer.append(" "); } } else if (s != 7) { addChar(writer, s, ch); } } if (s == 0) { writer.append("'"); } } finally { reader.close(); writer.close(); } }
From source file:com.theserverlabs.maven.utplsq.SureFireReport.java
/** * Writes the test xml with a header to the surefire report directory * /*from ww w. j ava2 s . c o m*/ * @param testXML * @throws IOException */ protected void writeXML(TestResults testResults, String suiteOrPackageName, long duration) throws IOException { // write the entire report to a file. We have to do it this way round // in order to know all the failures/sucesses to complete the // XML header element. Note that utPLSL does not provide any // timing info. String reportFile = "utplsql-" + suiteOrPackageName + "-report.xml"; FileWriter fw = null; try { File f = new File(surefireDir, reportFile); fw = new FileWriter(f); fw.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); fw.append("\n<testsuite name=\"" + suiteOrPackageName + "\" "); fw.append("tests=\""); fw.append(Integer.toString(testResults.getTestsRun())); fw.append("\" failures=\""); fw.append(Integer.toString(testResults.getFailures())); fw.append("\" skipped=\"0\" errors=\"0\" time=\"" + duration + "msec\">"); fw.append(testResults.getTestXML().toString()); fw.append("\n</testsuite>"); } finally { IOUtils.closeQuietly(fw); } log.debug("Writing Surefire file " + reportFile + " tests run " + testResults.getTestsRun()); }
From source file:SeedGenerator.FormDatabaseConfig.java
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed try {/*from w w w. jav a 2 s .c om*/ File newTextFile = new File("db.conf"); FileWriter fw = new FileWriter(newTextFile); fw.write("Hostname " + txtHostName.getText() + "\n"); fw.append("Port " + txtPort.getText() + "\n"); fw.append("Username " + txtUsername.getText() + "\n"); fw.append("Password " + txtPassword.getText() + "\n"); fw.write("Schema " + txtSchema.getText() + "\n"); fw.close(); JOptionPane.showMessageDialog(this, "Saved!"); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error, not saved!"); } // TODO add your handling code here: }
From source file:com.gnizr.web.action.export.ExportNetscapeBookmarks.java
private void writeFolderContent(FileWriter fwriter, Folder folder) throws IOException, NoSuchUserException { fwriter.append("<DT><H3>"); String fname = folder.getName(); if (FolderManager.MY_BOOKMARKS_LABEL.equals(fname)) { fname = "My Bookmarks"; } else if (FolderManager.IMPORTED_BOOKMARKS_LABEL.equals(fname)) { fname = "My RSS Imported"; }// w w w. ja v a2 s . c o m StringEscapeUtils.escapeHtml(fwriter, fname); fwriter.append("</H3>\n"); if (folder.getDescription() != null && folder.getDescription().length() > 0) { fwriter.append("<DD>"); String fdsp = folder.getDescription(); fdsp = FormatUtil.extractTextFromHtml(fdsp); StringEscapeUtils.escapeHtml(fwriter, fdsp.trim()); fwriter.append("\n"); } int offset = 0; int ppc = 100; DaoResult<Bookmark> result = folderManager.pageFolderContent(getLoggedInUser(), folder.getName(), offset, ppc); fwriter.append("<DL><p>\n"); while (offset < result.getSize()) { List<Bookmark> bookmarks = result.getResult(); for (Bookmark bm : bookmarks) { writeBookmark(fwriter, bm); offset++; } if (offset < result.getSize()) { result = folderManager.pageFolderContent(getLoggedInUser(), folder.getName(), offset, ppc); } else { break; } } fwriter.append("</DL><p>\n"); }
From source file:es.csic.iiia.planes.StatsCollector.java
/** * Addded by Ebtesam//ww w .ja v a 2 s. c om * write the result to .csv file */ public void writeCSV() { StringBuilder buf = new StringBuilder(); buf.append((int) taskStats.getN()).append(",").append((int) taskStats.getMin()).append(",") .append((int) taskStats.getMean()).append(",").append((int) taskStats.getMax()).append(","); buf.append((int) taskFoundStats.getN()).append(",").append((int) taskFoundStats.getMin()).append(",") .append((int) taskFoundStats.getMean()).append(",").append((int) taskFoundStats.getMax()) .append(","); buf.append(TimeTracker.getUserTime() / 1e6d).append("\n"); try { FileWriter writer = new FileWriter("resultsCSV1.csv", true); String[] results = buf.toString().split("\n"); for (String s : results) { writer.append(s); } writer.append("\n"); writer.append("\n"); writer.close(); } catch (IOException e) { } }
From source file:edu.clemson.lph.utils.CSVParserWrapper.java
private static void stripNewLines(File fIn, File fOut) { FileReader rIn = null;// w w w. j av a 2s . c o m FileWriter wOut = null; try { rIn = new FileReader(fIn); wOut = new FileWriter(fOut); int iQuoteCount = 0; char cLast = '\0'; char cThis = '\0'; int iThis = rIn.read(); while (iThis >= 0) { cThis = (char) iThis; if (cThis == '\"') { iQuoteCount++; } if (cThis == '\n' || cThis == '\r') { if ((iQuoteCount % 2) > 0) { // System.err.println("Removed new line after " + iQuoteCount + " quotes"); // new Exception("Removed new line after " + iQuoteCount + " quotes").printStackTrace(); // System.exit(1); cThis = ' '; } else { iQuoteCount = 0; } } wOut.append(cThis); cLast = cThis; iThis = rIn.read(); } } catch (IOException e) { // TODO Auto-generated catch block logger.error(e); } finally { try { if (rIn != null) rIn.close(); if (wOut != null) { wOut.flush(); wOut.close(); } } catch (IOException e) { logger.error(e); } } }
From source file:org.xwiki.mail.internal.FileSystemMailContentStoreTest.java
@Test public void loadMessage() throws Exception { String batchId = UUID.randomUUID().toString(); String messageId = "ar1vm0Wca42E/dDn3dsH8ogs3/s="; String mimeMessageId = "<1128820400.0.1419205781342.JavaMail.contact@xwiki.org>"; File tempDir = new File(TEMPORARY_DIRECTORY); File batchDirectory = new File(new File(tempDir, this.mocker.getComponentUnderTest().ROOT_DIRECTORY), URLEncoder.encode(batchId, "UTF-8")); batchDirectory.mkdirs();//from w ww .j a v a 2s .co m File messageFile = new File(batchDirectory, URLEncoder.encode(messageId, "UTF-8")); messageFile.createNewFile(); String newLine = System.getProperty("line.separator"); FileWriter fileWriter = new FileWriter(messageFile, true); // Unique string is <hashcode>.<id>.<currentTime>.JavaMail.<suffix> fileWriter.append("Message-ID: " + mimeMessageId + newLine); fileWriter.append("MIME-Version: 1.0" + newLine); fileWriter.append("Content-Type: text/plain; charset=us-ascii" + newLine); fileWriter.append("Content-Transfer-Encoding: 7bit" + newLine + newLine); fileWriter.append("Lorem ipsum dolor sit amet, consectetur adipiscing elit"); fileWriter.close(); Session session = Session.getInstance(new Properties()); MimeMessage message = this.mocker.getComponentUnderTest().load(session, batchId, messageId); assertEquals(mimeMessageId, message.getMessageID()); assertEquals("Lorem ipsum dolor sit amet, consectetur adipiscing elit", message.getContent()); }
From source file:com.att.aro.main.ProperSessionTerminationPanel.java
/** * method writes a provided key values in to the file writer. * /*from ww w .j a v a2 s .c o m*/ * @param writer * @param key * @param value * @param value1 * @throws IOException */ private void addKeyValue(FileWriter writer, String key, String value) throws IOException { final String lineSep = System.getProperty(rb.getString("statics.csvLine.seperator")); writer.append(key); writer.append(','); writer.append(value); writer.append(lineSep); }
From source file:org.sakaiproject.search.index.impl.SegmentState.java
/** * @param timestampFile//from www .j a v a 2 s . c o m * @throws IOException */ public void save(File checksumFile) throws IOException { File tmpFile = new File(checksumFile.getAbsolutePath() + ".tmp"); FileWriter fw = null; try { fw = new FileWriter(tmpFile); fw.append(VERSION).append("\n"); fw.append(String.valueOf(timeStamp)).append("\n"); for (Iterator<FileRecord> i = fileRecords.values().iterator(); i.hasNext();) { FileRecord fr = i.next(); fw.append(fr.path).append(";"); fw.append(fr.checksum).append(";"); fw.append(String.valueOf(fr.length)).append(";"); fw.append(String.valueOf(fr.lastMod)).append(";\n"); } } catch (IOException e) { throw new IOException(); } finally { if (fw != null) { fw.close(); } } if (!tmpFile.renameTo(checksumFile)) { log.warn("unable to rename " + tmpFile.getPath() + " to " + checksumFile.getPath()); } }