List of usage examples for java.io Writer close
public abstract void close() throws IOException;
From source file:com.github.jarscanner.XmlGenerator.java
public void generate() { Properties p = new Properties(); p.setProperty("resource.loader", "string"); p.setProperty("resource.loader.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader"); Velocity.init(p);// w ww.j a v a 2 s . c o m Template template = getTemplate("com/github/jarscanner/jar-data.vm"); VelocityContext context = new VelocityContext(); context.put("duplicatesImpl", duplicatesImpl); context.put("duplicatesBridges", duplicatesBridges); try { Writer writer = new OutputStreamWriter(new FileOutputStream(outXml), "utf-8"); template.merge(context, writer); writer.flush(); writer.close(); } catch (IOException e) { LOG.error(e, e.getMessage()); } }
From source file:au.edu.uq.cmm.benny.Benny.java
private void respond(HttpServletResponse resp, int status, String msg) throws IOException { resp.setContentType("text/plain"); resp.setStatus(status);// w ww .j a v a2s. com Writer w = resp.getWriter(); try { w.write(msg + "\r\n"); } finally { w.close(); } }
From source file:com.centeractive.ws.server.endpoint.GenericSoapMessage.java
@Override public void writeTo(OutputStream outputStream) throws IOException { Writer writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); String message = XmlUtils.sourceToXmlString(source); writer.write(message);/* ww w .ja va 2s . com*/ writer.flush(); writer.close(); }
From source file:org.b3mn.poem.Representation.java
public static void extractJsonFromDatabase(String serverUrl) throws IOException { ScrollableResults contents = Persistance.getSession().createSQLQuery("SELECT content.erdf FROM content") .setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY); int count = 0; while (contents.next()) { String content = (String) contents.get(0); Writer writer = new FileWriter( "C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/json/" + count + ".json"); if (isJson(content)) { } else {//from w ww .j ava2s . c o m content = erdfToJson(content, serverUrl); } if (content == null || content.indexOf("BPMNDiagram") == -1) continue; String[] labels = new String[] { "name", "documentation", "title", "description", "pooldocumentation", "conditionexpression", "text", "state" }; for (String prop : labels) content = content.replaceAll("\"" + prop + "\":\"([\\w\\W^\"]*?(\\\\\")?[\\w\\W^\"]*?)*?\"", "\"" + prop + "\":\"\""); FileCopyUtils.copy(content, writer); writer.close(); if (++count % 10 == 0) { //flush a batch of updates and release memory: Persistance.getSession().flush(); Persistance.getSession().clear(); } System.gc(); } Persistance.commit(); }
From source file:bazaar4idea.command.BzrCommitCommand.java
private File saveCommitMessage() throws IOException { File systemDir = new File(PathManager.getSystemPath()); File tempFile = new File(systemDir, TEMP_FILE_NAME); Writer output = new BufferedWriter(new FileWriter(tempFile, false)); try {// w ww .j a va2s . c o m output.write(message); output.flush(); } finally { output.close(); } tempFile.deleteOnExit(); return tempFile; }
From source file:de.andrena.tools.macker.plugin.CommandLineFileTest.java
private void writeArgsFile(List<String> lines) throws IOException { Writer out = new OutputStreamWriter(new FileOutputStream(TEST_FILE), "UTF-8"); IOUtils.writeLines(lines, "\n", out); out.flush();/*from w ww. j a v a 2 s . com*/ out.close(); }
From source file:de.tudarmstadt.ukp.wikipedia.parser.html.HtmlWriter.java
public static void writeFile(String filename, String encoding, String text) { File outFile = new File(filename); Writer destFile = null; try {//from w ww .j a v a2s . co m destFile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), encoding)); } catch (UnsupportedEncodingException e1) { logger.error("Unsupported encoding exception while opening file " + outFile.getAbsolutePath()); e1.printStackTrace(); } catch (FileNotFoundException e1) { logger.error("File " + outFile.getAbsolutePath() + " not found."); e1.printStackTrace(); } try { destFile.write(text); } catch (IOException e) { logger.error("IO exception while writing file " + outFile.getAbsolutePath()); e.printStackTrace(); } try { destFile.close(); } catch (IOException e) { logger.error("IO exception while closing file " + outFile.getAbsolutePath()); e.printStackTrace(); } }
From source file:com.dotosoft.dotoquiz.tools.config.Settings.java
public boolean saveSettings() { try {/*from ww w .ja v a2 s. c om*/ Writer writer = new FileWriter(fileconfig); yaml.dump(this, writer); writer.close(); } catch (Exception ex) { ex.printStackTrace(); return false; } return true; }
From source file:gdv.xport.util.NullFormatterTest.java
/** * Test-Methode fuer {@link NullFormatter#notice(gdv.xport.satz.Satz)}. * Hier testen wir im Wesentlichen die Eigenschaften als * {@link ImportListener}.//w w w . j a va 2 s. c om * * @throws IOException Signals that an I/O exception has occurred. */ @IntegrationTest @Test public void testNotice() throws IOException { File output = File.createTempFile("testNotice", ".txt"); Writer writer = new OutputStreamWriter(new FileOutputStream(output), "ISO-8859-1"); try { exportMusterdatei(new NullFormatter(writer)); writer.close(); FileTester.assertContentEquals(MUSTERDATEI, output, "ISO-8859-1"); } finally { log.info(output + " was " + (output.delete() ? "successful" : "not") + " deleted"); } }
From source file:com.moss.posixfifosockets.testharness.JavaTestClient.java
@Override String send(String message) throws Exception { log("Connecting to server"); socket = PosixFifoSocket.newClientConnection(address, 1000); log("Using socket " + socket); log("Opening output "); Writer w = new OutputStreamWriter(socket.out()); log("Writing message "); w.write(message);/*from www. j a v a 2 s. c om*/ log("Closing output"); w.close(); log("Opening response"); BufferedReader reader = new BufferedReader(new InputStreamReader(socket.in())); char[] b = new char[1024]; log("Reading response"); StringBuilder text = new StringBuilder(); for (int x = reader.read(b); x != -1; x = reader.read(b)) { text.append(b, 0, x); } log("Closing response"); reader.close(); log("Done (received " + message + ")"); // String response = reader.readLine(); // reader.close(); socket.close(); // System.out.println("Response " + response); return text.toString(); }