List of usage examples for java.io OutputStreamWriter OutputStreamWriter
public OutputStreamWriter(OutputStream out, CharsetEncoder enc)
From source file:net.hamnaberg.json.Template.java
public void writeTo(OutputStream stream) throws IOException { writeTo(new OutputStreamWriter(stream, Charsets.UTF_8)); }
From source file:de.bund.bfr.knime.pmm.common.chart.ChartUtilities.java
public static void saveChartAs(JFreeChart chart, String fileName, int width, int height) { if (fileName.toLowerCase().endsWith(".png")) { try {/* w w w. java 2 s . com*/ org.jfree.chart.ChartUtilities.writeChartAsPNG(new FileOutputStream(fileName), chart, width, height); } catch (IOException e) { e.printStackTrace(); } } else if (fileName.toLowerCase().endsWith(".svg")) { try { DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); Document document = domImpl.createDocument(null, "svg", null); SVGGraphics2D svgGenerator = new SVGGraphics2D(document); Writer outsvg = new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8); chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, width, height)); svgGenerator.stream(outsvg, true); outsvg.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (SVGGraphics2DIOException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:io.pivotal.strepsirrhini.chaosloris.docs.MarkdownWriterResolver.java
@Override public Writer resolve(String operationName, String snippetName, RestDocumentationContext context) throws IOException { RestDocumentationContextPlaceholderResolver placeholderResolver = new RestDocumentationContextPlaceholderResolver( context);//from w w w . j av a 2s. co m File outputFile = resolveFile( this.propertyPlaceholderHelper.replacePlaceholders(operationName, placeholderResolver), snippetName + ".md", context); if (outputFile != null) { createDirectoriesIfNecessary(outputFile); return new OutputStreamWriter(new FileOutputStream(outputFile), this.encoding); } else { return new OutputStreamWriter(System.out, this.encoding); } }
From source file:com.caorongjin.pingguo.Pingguo.java
private static BufferedWriter _createWriter(String fileName) throws Exception { OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(fileName), "UTF8"); return new BufferedWriter(osw); }
From source file:Main.java
public void print(OutputStream out) throws IOException, TransformerException { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform(new DOMSource(this.doc), new StreamResult(new OutputStreamWriter(out, "UTF-8"))); }
From source file:biz.c24.io.spring.batch.writer.source.FileWriterSource.java
@Override public void initialise(StepExecution stepExecution) { // Extract the name of the file we're supposed to be writing to String fileName = resource != null ? resource.getPath() : stepExecution.getJobParameters().getString("output.file"); // Remove any leading file:// if it exists if (fileName.startsWith("file://")) { fileName = fileName.substring("file://".length()); }//from www . j a v a 2s . c o m try { outputFile = new OutputStreamWriter(new FileOutputStream(fileName), getEncoding()); } catch (IOException ioEx) { throw new RuntimeException(ioEx); } }
From source file:com.boazlev.waze.web.WazeServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOG.info("doPost"); response.setContentType("text/xml; charset=UTF-8"); PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF8"), true); StringBuilder sb = new StringBuilder(); Collection<EnhancedBase> enhancedBases = app.get(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\n"); sb.append("<?xml-stylesheet type=\"text/xsl\" href=\"out.xslt\"?>").append("\n"); sb.append("<catalog>").append("\n"); if (enhancedBases != null) { for (EnhancedBase enhancedBase : enhancedBases) { String city = enhancedBase.getCity(); String neighborhood = enhancedBase.getNeighborhood(); LOG.info("Parsing - " + city + " / " + neighborhood); MyBase myBase = enhancedBase.getMyBase(); if (myBase != null) { PoiMarkerElement[] poimarkers = myBase.getPoimarkers(); for (PoiMarkerElement poiMarkerElement : poimarkers) { PoiElement[] pois = poiMarkerElement.getPois(); if (pois != null) { for (PoiElement poiElement : pois) { String id = poiElement.getId(); if ("project".equals(poiElement.getType())) { sb.append("<cd>").append("\n"); sb.append(toXmlData("xid", id)).append("\n"); Info info = poiElement.getInfo(); if (info != null) { sb.append(toXmlData("city", city)).append("\n"); sb.append(toXmlData("neighborhood", neighborhood)).append("\n"); sb.append(toXmlData("marketing", info.getMarketingstage())).append("\n"); sb.append(toXmlData("buildingStage", info.getBuildingstage())).append("\n"); sb.append(toXmlData("location", info.getLocation())).append("\n"); sb.append(toXmlData("lat", poiElement.getLat().toString())).append("\n"); sb.append(toXmlData("lng", poiElement.getLng().toString())).append("\n"); sb.append(toXmlData("description", info.getDescription())).append("\n"); }//from w ww .jav a2s . c om sb.append("</cd>").append("\n"); } } } } } } } sb.append("</catalog>"); out.println(sb.toString()); out.flush(); LOG.fine(sb.toString()); LOG.info("Done"); }
From source file:at.orz.arangodb.http.JsonSequenceEntity.java
public void writeTo(OutputStream outstream) throws IOException { if (outstream == null) { throw new IllegalArgumentException("Output stream may not be null"); }/*from w w w .ja v a2 s.c o m*/ BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(outstream, "UTF-8")); while (it.hasNext()) { Object value = it.next(); gson.toJson(value, writer); writer.newLine(); } writer.flush(); } finally { } }
From source file:uk.org.iay.mdq.server.ResultTextView.java
@Override public void render(final Map<String, ?> model, final HttpServletRequest request, final HttpServletResponse response) throws Exception { log.debug("rendering as {}", getContentType()); final Result result = (Result) model.get("result"); if (result.isNotFound()) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return;/*ww w . j a v a 2s .c o m*/ } OutputStream out = response.getOutputStream(); response.setContentType(new MediaType("text", "plain", Charset.forName("UTF-8")).toString()); final Writer w = new OutputStreamWriter(out, Charset.forName("UTF-8")); final Representation norm = result.getRepresentation(); final byte[] bytes = norm.getBytes(); w.write("Query result is:\n"); w.write(" " + bytes.length + " bytes\n"); w.write(" ETag is " + norm.getETag() + "\n"); w.write("\n"); w.write(new String(bytes, Charset.forName("UTF-8"))); }
From source file:de.atomfrede.tools.evalutation.tools.plot.util.PlotUtil.java
public static void saveChartAsSVG(File file, JFreeChart chart, int width, int height) throws Exception { Writer out = null;// w w w.j ava 2 s. co m try { DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); String svgNS = "http://www.w3.org/2000/svg"; org.w3c.dom.Document document = domImpl.createDocument(svgNS, "svg", null); SVGGraphics2D svgGenerator = new SVGGraphics2D(document); svgGenerator.getGeneratorContext().setPrecision(6); chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, width, height), null); boolean useCSS = true; out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); svgGenerator.stream(out, useCSS); } catch (UnsupportedEncodingException enc) { log.error(enc); } catch (FileNotFoundException fnf) { log.error(fnf); } catch (SVGGraphics2DIOException e) { log.error(e); } catch (DOMException dome) { log.error(dome); } finally { if (out != null) out.close(); } }