List of usage examples for java.io OutputStreamWriter OutputStreamWriter
public OutputStreamWriter(OutputStream out, CharsetEncoder enc)
From source file:Main.java
/** * Stores document into specified file/*ww w .j ava 2 s .c o m*/ * @param document XML document * @param transformer Transformer object to store document * @param file File where this method stores XML document * @param encoding Encoding in with document should be stored * @throws IOException If cannot store because of IO error * @throws TransformerException If cannot store because transformer error */ public static void storeDocument(Document document, Transformer transformer, File file, String encoding) throws IOException, TransformerException { FileOutputStream stream = null; OutputStreamWriter writer = null; try { if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); } stream = new FileOutputStream(file); writer = new OutputStreamWriter(stream, encoding); storeDocument(document, transformer, writer); } finally { if (stream != null) { stream.close(); } } }
From source file:eu.vital.vitalcep.cep.CepProcess.java
public void startCEP() throws FileNotFoundException, IOException { this.fileName = RandomStringUtils.randomAlphanumeric(8); try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(cepFolder//+"/"+dolceFile + "/" + fileName + "_dolce"), "utf-8"))) { writer.write(dolce);//from ww w.j a va 2s. c om writer.close(); String cmd = cepFolder + "/bcep -d " + cepFolder + "/" + fileName + "_dolce -mi " + mqin + " -mo " + mqout + " -f " + cepFolder + "/" + confFile + " &>/dev/null &"; logger.debug("starting bCEP with command: " + cmd); try { Process pr = Runtime.getRuntime().exec(cmd); is = pr.getInputStream(); es = pr.getErrorStream(); be = new Buffer_eraser(); be.start(); PID = getPid(pr); if (PID == -1) { java.util.logging.Logger.getLogger(CepProcess.class.getName()).log(Level.SEVERE, "couldn't create the process"); isUp = false; } else { isUp = true; logger.debug("new bCEP created: " + PID); logger.debug("mqin: " + mqin); logger.debug("mqout: " + mqout); } } catch (IOException e) { java.util.logging.Logger.getLogger(CepProcess.class.getName()).log(Level.SEVERE, e.getMessage()); PID = -3; isUp = false; } } catch (IOException ex) { PID = -2; isUp = false; this.fileName = ""; java.util.logging.Logger.getLogger(CepProcess.class.getName()).log(Level.SEVERE, ex.getMessage()); } }
From source file:lv.semti.morphology.attributes.AttributeValues.java
public void describe() { PrintWriter izeja;/* w ww.jav a 2 s. co m*/ try { izeja = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8")); this.describe(izeja); izeja.flush(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:com.fengduo.bee.commons.component.ComponentController.java
@ExceptionHandler(Throwable.class) public ModelAndView handleIOException(Throwable e) throws Throwable { if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) { throw e;/*from www . j a va 2s . com*/ } if (request == null && response == null) { throw e; } if (request == null && response != null) { response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=UTF-8"); OutputStream out = response.getOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "utf-8")); pw.println("{\"code\":1,\"msg\":\",?!\",\"data\":\"\"}"); pw.flush(); pw.close(); } ModelAndView mav = new ModelAndView(); // if (InvokeTypeTools.isAjax(request)) { // return createJsonMav("server exceptin or error", ResultCode.ERROR, // e.getMessage()); // } mav.addObject("exception", e.getCause() == null ? StringUtils.EMPTY : e.getCause().toString()); mav.addObject("msg", StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage()); mav.addObject("stackTrace", e.getStackTrace().toString()); if (request.getRequestURI() != null) { mav.addObject("url", request.getRequestURI().toString()); } mav.setViewName("error"); return mav; }
From source file:org.cloudfoundry.client.lib.util.StringHttpMessageConverterWithoutMediaType.java
@Override protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException { if (writeAcceptCharset) { outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets()); }//w w w . ja v a 2 s . c o m MediaType contentType = outputMessage.getHeaders().getContentType(); Charset charset = contentType != null && contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET; FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), charset)); }
From source file:seava.j4e.web.controller.ui.extjs.DependencyLoader.java
public void packFrameCmp(String bundle, String name, File file) throws Exception { List<String> list = new ArrayList<String>(); this.resolveFrameDependencies(bundle, name, null, list, null); Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); // ISO-8859-1 try {/*ww w. j av a 2 s. co m*/ for (String dep : list) { this.writeContentCmp(dep, writer); } } finally { writer.close(); } }
From source file:edu.lafayette.metadb.web.search.SearchServlet.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) *//*www. j ava 2s.c o m*/ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF8"), true); JSONObject output = new JSONObject(); ArrayList<String> tokens = new ArrayList<String>(); try { String options = request.getParameter("search-options"); String projname = ""; String query = request.getParameter("query"); if (options.equals("current")) projname = (String) request.getSession(false).getAttribute(Global.SESSION_PROJECT); if (query != null && !query.equals("")) { ArrayList<Item> resultList = SearchDAO.search(projname, query); tokens.addAll(MetaDbHelper.getStringTokens(query)); output.put("size", resultList.size()); if (resultList.isEmpty()) output.put("data", "No entry found with query \"" + query + "\""); else output.put("data", this.getFormattedResult(resultList, tokens)); } else { output.put("data", "Please type in some keywords"); output.put("size", 0); } output.put("queries", tokens); out.print(output); } catch (Exception e) { MetaDbHelper.logEvent(e); } out.flush(); }
From source file:Main.java
/** * @param dom//from ww w. ja v a 2 s .com * @param outFile */ public static void writeDomToFile(Element dom, File outFile) { try { TransformerFactory transFact = TransformerFactory.newInstance(); Transformer transformer = transFact.newTransformer(); DOMSource source = new DOMSource(dom); StreamResult result; result = new StreamResult( new OutputStreamWriter(new FileOutputStream(outFile), System.getProperty("file.encoding"))); transformer.transform(source, result); } catch (Exception e) { throw new RuntimeException( "Could not write dom tree '" + dom.getBaseURI() + "' to file '" + outFile.getName() + "'!", e); } }
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);/* w ww .ja v a 2 s. c o m*/ writer.flush(); writer.close(); }
From source file:juicebox.tools.utils.juicer.apa.APAUtils.java
public static void saveListText(String filename, List<Double> array) { Writer writer = null;//from ww w .ja v a 2 s. c om try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "utf-8")); for (double val : array) { writer.write(val + " "); } writer.write("\n"); } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (writer != null) writer.close(); } catch (Exception ex) { ex.printStackTrace(); } } }