List of usage examples for java.io Writer close
public abstract void close() throws IOException;
From source file:com.c4om.autoconf.ulysses.configanalyzer.guilauncher.TemporaryChangesetFilesSavingGUILauncher.java
/** * This method generates the catalog file and stores it into the temporary folder * @param temporaryFolder the temporary folder * @param changesetPaths URIs poiting to changeset files * @throws CatalogGenerationException if there is any problem at catalog generation *//*w w w.j a v a2 s . c om*/ private void generateCatalog(File temporaryFolder, List<URI> changesetPaths) throws CatalogGenerationException { try { Map<QName, List<URI>> variables = ImmutableMap.of(new QName(FILES_PARAMETER_NAME), changesetPaths); String catalogFileString = saxonQuery(generateCatalogQuery, variables); FileOutputStream fileOutputStream = new FileOutputStream( new File(temporaryFolder, CATALOG_XML_FILE_NAME)); Writer writer = new XmlStreamWriter(fileOutputStream, "UTF-8"); writer.write(catalogFileString); writer.close(); } catch (IOException | SaxonApiException e) { throw new CatalogGenerationException(e); } }
From source file:de.cosmocode.palava.core.Main.java
private void persistState() { if (options.getStateFile() == null) return;/*from ww w. j av a2 s . co m*/ try { final State state = framework == null ? State.FAILED : framework.currentState(); final Writer writer = new FileWriter(options.getStateFile()); try { IOUtils.write(state.name() + "\n", writer); } finally { writer.close(); } } catch (IOException e) { throw new IllegalArgumentException("cannot persist state to file", e); } }
From source file:org.nobel.highriseapi.mapper.SimpleXmlHttpMessageConverter.java
@Override protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { Writer out = new OutputStreamWriter(outputMessage.getBody(), getCharset(outputMessage.getHeaders())); try {//from www . j a va 2 s. c o m this.serializer.write(o, out); out.close(); } catch (Exception ex) { throw new HttpMessageNotWritableException("Could not write [" + o + "]", ex); } }
From source file:org.apache.juneau.rest.client.RestRequestEntity.java
@Override /* BasicHttpEntity */ public void writeTo(OutputStream os) throws IOException { if (output instanceof InputStream) { IOPipe.create(output, os).closeOut().run(); } else if (output instanceof Reader) { IOPipe.create(output, new OutputStreamWriter(os, IOUtils.UTF8)).closeOut().run(); } else {// w ww . jav a 2 s . c o m try { if (serializer == null) { // If no serializer specified, just close the stream. os.close(); } else if (!serializer.isWriterSerializer()) { OutputStreamSerializer s2 = (OutputStreamSerializer) serializer; s2.serialize(output, os); os.flush(); os.close(); } else { Writer w = new OutputStreamWriter(os, IOUtils.UTF8); WriterSerializer s2 = (WriterSerializer) serializer; s2.serialize(output, w); w.flush(); w.close(); } } catch (SerializeException e) { throw new org.apache.juneau.rest.client.RestCallException(e); } } }
From source file:com.viddu.handlebars.HandlebarsMojo.java
public void execute() throws MojoExecutionException { File outDir = outputDirectory; File inDir = inputDirectory;//w w w. j a v a2 s . c om File hbrLib = handlebarsLibrary; // Load the handlebars library into the scope Scriptable globalScope = loadHandlebarsLibrary(hbrLib); // Check if output path is a directory and create if it does not exist. if (!outDir.exists()) { outDir.mkdir(); } if (outDir.exists() && !outDir.isDirectory()) { throw new MojoExecutionException("OutputDir:" + outDir.toString() + "is not Directory"); } // Iterate over files in the input Directory if (inDir.isDirectory()) { for (File file : HandlebarsFileUtil.loadHandlebarTemplates(inDir)) { try { String output = compile(globalScope, file); Writer fwriter = new BufferedWriter(new FileWriter(new File(outDir, file.getName()))); fwriter.write(output); fwriter.close(); } catch (IOException e) { throw new MojoExecutionException("Exception creating compiled File", e); } } } else { throw new MojoExecutionException("Input Directory:" + inDir.toString() + "is not Directory"); } }
From source file:com.apress.progwt.server.web.controllers.GearsLocalServerManifestController.java
/** * { "betaManifestVersion": 1, "version": "my_version_string", * "entries": [ { "url": "go_offline.html"}, { "url": * "go_offline.js"}, { "url": "gears_init.js"} ] } * // w w w. j ava 2 s. c om * @param output * @throws IOException * @throws JSONException */ @RequestMapping(method = RequestMethod.GET) public void forumsHandler(Writer output) throws IOException, JSONException { if (manifest == null) { manifest = createManifest(); } output.append(manifest); output.close(); }
From source file:com.tinspx.util.json.JSONParserTest.java
static void writeIndentingOut(Object value) throws IOException { Writer w = new OutputStreamWriter(System.out); IndentingWriter.create().writeTo(w, value); w.flush();/* w ww.j av a2 s . c o m*/ w.close(); System.out.println(); }
From source file:cz.autoclient.league_of_legends.DataLoader.java
public void toFile(File file) { try {/*from w w w.ja v a2 s. c om*/ Writer w = new FileWriter(file); data.write(w); w.close(); } catch (JSONException | IOException ex) { throw new Error("Couldn't write to file: " + ex); } }
From source file:gumga.framework.application.template.GumgaFreemarkerTemplateEngineTest.java
@Test public void testParseToFile() throws Exception { Map<String, Object> values = new HashMap<>(); String name = "Lara Croft"; values.put("name", name); values.put("age", new Integer(35)); File file = new File(OUTPUT_FOLDER + "/testResult.txt"); FileOutputStream fos = new FileOutputStream(file); Writer writer = new OutputStreamWriter(fos); try {/*from w w w . j a v a 2 s .c o m*/ gumgaFreemarkerTemplateEngineService.parse(values, "testTemplate.ftl", writer); } finally { fos.close(); writer.flush(); writer.close(); } assertTrue(file.exists()); }
From source file:no.dusken.aranea.view.FeedView.java
protected void renderMergedOutputModel(Map map, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("application/rss+xml"); response.setCharacterEncoding("UTF-8"); List<Page> pages = (List<Page>) map.get("pages"); Section section = (Section) map.get("section"); feedtype = (String) map.get("feedType"); log.debug("Feedtype is {}", feedtype); if (feedtype == null) feedtype = DEFAULT_FEEDTYPE;// ww w. j a v a 2s . c o m List<SyndEntry> entries = new ArrayList<SyndEntry>(); SyndFeed feed = new SyndFeedImpl(); feed.setFeedType(feedtype); feed.setEncoding("UTF-8"); if (section != null) { feed.setTitle(section.getName() + " | Under Dusken"); } else { feed.setTitle("Under Dusken"); } feed.setLink("http://" + hostname); feed.setDescription("Nyheter fra Under Dusken, studentavisa i Trondheim"); // log.debug(pages); if (pages != null) { for (Page page : pages) { SyndEntry entry = new SyndEntryImpl(); entry.setTitle(page.getTitle()); entry.setPublishedDate(page.getTimePublished().getTime()); if (page instanceof Article) { Article article = (Article) page; if (article.getIssue() != null) { entry.setLink("http://" + hostname + request.getContextPath() + "/" + article.getParent().getName().toLowerCase() + "/" + article.getIssue().getFromDate().get(Calendar.YEAR) + "/" + article.getIssue().getIssue() + "/" + article.getID() + "/" + article.getSafeTitle()); } else { entry.setLink("http://" + hostname + request.getContextPath() + "/" + article.getParent().getName().toLowerCase() + "/" + article.getID() + "/" + article.getSafeTitle()); } } else { entry.setLink("http://" + hostname + request.getContextPath() + "/" + page.getClass().getSimpleName() + "/" + page.getID() + "/" + page.getSafeTitle()); } // does not validate in feedvalidator: // http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.underdusken.no%2Fdusken%2Ffeed%2Fud.xml // entry.setUpdatedDate(page.getModified().getTime()); // people List<SyndPerson> authors = new ArrayList<SyndPerson>(); for (Person p : page.getAuthors()) { SyndPerson sp = new SyndPersonImpl(); sp.setName(p.getFirstname() + " " + p.getSurname()); sp.setEmail(p.getUsername() + "@underdusken.no"); authors.add(sp); } entry.setAuthors(authors); // description: SyndContent description = new SyndContentImpl(); description.setType("text/html"); //remove htmltags description .setValue(page.getSummary() == null ? "" : page.getSummary().replaceAll("\\<.*?\\>", "")); entry.setDescription(description); entries.add(entry); } } feed.setEntries(entries); Writer writer = response.getWriter(); SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, writer); writer.close(); }