List of usage examples for java.io CharArrayWriter toString
public String toString()
From source file:phex.common.log.PhexLogger.java
/** * Gets the stack trace of an exception as string. * @param aThrowable the Throwable * @return the stack trace of the exception *//*from w w w . j a v a 2 s.c om*/ private static String getStackTrace(Throwable aThrowable) { CharArrayWriter buffer = new CharArrayWriter(); PrintWriter printWriter = new PrintWriter(buffer); // recursively print nested exceptions to a String while (aThrowable != null) { aThrowable.printStackTrace(printWriter); if (aThrowable instanceof InvocationTargetException) { aThrowable = ((InvocationTargetException) aThrowable).getTargetException(); } else { aThrowable = null; } } return buffer.toString(); }
From source file:com.jigsforjava.string.StringUtils.java
/** * Converts a camel case string into a lower-case, delimiter-separated * string. For example, a call of toSeparatedString("ACamelCaseString, '_') * returns a_camel_case_string.//from w w w. j a va2s.c o m * * @param camelCaseString * a String in camel case to delimit. * @param delimiter * the character used to separate the string. * @return a String where capitals in the original are prefixed with the * given delimiter. */ public static String toSeparatedString(String camelCaseString, char delimiter) { CharArrayWriter result = new CharArrayWriter(); char[] chars = camelCaseString.toCharArray(); for (int i = 0; i < chars.length; ++i) { if (chars[i] != delimiter && Character.isUpperCase(chars[i]) && i > 0) { if ((i < chars.length - 1) && (!Character.isUpperCase(chars[i + 1]) && chars[i + 1] != delimiter) && chars[i - 1] != delimiter) result.write(delimiter); else if (!Character.isUpperCase(chars[i - 1]) && chars[i - 1] != delimiter) result.write(delimiter); } result.write(chars[i]); } return result.toString().toLowerCase(); }
From source file:org.apache.taverna.scufl2.translator.t2flow.T2FlowParser.java
public static String elementToXML(Element element) { try {//w ww . j a v a2s . c o m Transformer transformer = getTransformer(); CharArrayWriter writer = new CharArrayWriter(); transformer.transform(new DOMSource(element), new StreamResult(writer)); return writer.toString(); } catch (TransformerException e) { throw new IllegalStateException("Can't write XML", e); } }
From source file:org.topazproject.ambra.auth.web.UsernameReplacementWithGuidFilter.java
private String dumpResponse(final CharResponseWrapper wrapper) throws IOException { log.debug("Response ContentType:" + wrapper.getContentType()); CharArrayWriter caw = new CharArrayWriter(); caw.write(wrapper.toString());//from w w w . ja v a 2 s .c o m final String response = caw.toString(); log.debug("Response generated:"); log.debug(response); return response; }
From source file:net.wastl.webmail.xml.XMLGenericModel.java
public synchronized void setException(Exception ex) { Element exception = root.createElement("EXCEPTION"); Element ex_message = root.createElement("EX_MESSAGE"); Element ex_stacktrace = root.createElement("EX_STACKTRACE"); exception.appendChild(ex_message);//from w w w.j a v a 2 s. co m exception.appendChild(ex_stacktrace); Text msg = root.createTextNode(ex.getMessage()); ex_message.appendChild(msg); String my_stack = ""; CharArrayWriter cstream = new CharArrayWriter(); ex.printStackTrace(new PrintWriter(cstream)); my_stack = cstream.toString(); CDATASection stack = root.createCDATASection(my_stack); ex_stacktrace.appendChild(stack); NodeList nl = getNodeListXPath("//EXCEPTION"); if (nl.getLength() > 0) { statedata.replaceChild(exception, nl.item(0)); } else { statedata.appendChild(exception); } invalidateCache(); //XMLCommon.debugXML(root); }
From source file:com.metaparadigm.jsonrpc.JSONRPCResult.java
@Override public String toString() { try {//from w w w . j ava 2 s .c om JSONObject o = new JSONObject(); if (errorCode == CODE_SUCCESS) { o.put("id", id); o.put("result", result); } else if (errorCode == CODE_REMOTE_EXCEPTION) { Throwable e = (Throwable) result; CharArrayWriter caw = new CharArrayWriter(); e.printStackTrace(new PrintWriter(caw)); JSONObject err = new JSONObject(); err.put("code", new Integer(errorCode)); err.put("msg", e.getMessage()); err.put("trace", caw.toString()); o.put("id", id); o.put("error", err); } else { JSONObject err = new JSONObject(); err.put("code", new Integer(errorCode)); err.put("msg", result); o.put("id", id); o.put("error", err); } return o.toString(); } catch (Exception exc) { exc.printStackTrace(); } return null; }
From source file:de.betterform.agent.web.filter.XSLTFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; ServletContext servletContext = filterConfig.getServletContext(); /* TODO: clean up, styleFile is never used */ String stylePath = null;// ww w .java 2s.c om try { stylePath = WebFactory.getRealPath(xsltPath, servletContext); } catch (XFormsConfigException e) { throw new ServletException(e); } File styleFile = new File(stylePath, xslFile); PrintWriter out = response.getWriter(); CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse) response); try { URI uri = new File(WebFactory.getRealPath(xsltPath, servletContext)).toURI().resolve(new URI(xslFile)); XSLTGenerator generator = WebFactory.setupTransformer(uri, servletContext); wrapper.setContentType("text/html"); chain.doFilter(request, wrapper); StringReader sr = new StringReader(wrapper.toString()); generator.setInput(sr); // Source xmlSource = new StreamSource((Reader) sr); CharArrayWriter caw = new CharArrayWriter(); generator.setOutput(caw); // StreamResult result = new StreamResult(caw); // transformer.transform(xmlSource, result); generator.generate(); response.setContentLength(caw.toString().length()); out.write(caw.toString()); } catch (URISyntaxException e) { out.println(e.toString()); out.write(wrapper.toString()); } catch (XFormsException e) { out.println(e.toString()); out.write(wrapper.toString()); } }
From source file:org.couch4j.http.HttpConnectionManager.java
private JSONArray arrayFromResponseStream(HttpEntity entity) throws IOException { InputStream is = entity.getContent(); Reader reader = new InputStreamReader(is, EntityUtils.getContentCharSet(entity)); CharArrayWriter w = new CharArrayWriter(); StreamUtils.copy(reader, w);/* ww w. j a v a 2s. c o m*/ JSONArray json = JSONArray.fromObject(w.toString()); StreamUtils.closeSilently(reader); StreamUtils.closeSilently(w); entity.consumeContent(); // finish return json; }
From source file:org.couch4j.http.HttpConnectionManager.java
private JSONObject fromResponseStream(HttpEntity entity) throws IOException { InputStream is = entity.getContent(); Reader reader = new InputStreamReader(is, EntityUtils.getContentCharSet(entity)); CharArrayWriter w = new CharArrayWriter(); StreamUtils.copy(reader, w);//from www.j av a 2 s.co m JSONObject json = JSONObject.fromObject(w.toString()); StreamUtils.closeSilently(reader); StreamUtils.closeSilently(w); entity.consumeContent(); // finish return json; }
From source file:org.milyn.SmooksStandaloneTest.java
public void test_Standalone_CodeConfig_2() throws SAXException, IOException { Smooks smooks = new Smooks(); // Add 2 useragents and configure them with profiles... SmooksUtil.registerProfileSet(/* w ww .j av a 2s . com*/ DefaultProfileSet.create("message-target1", new String[] { "profile1", "profile2" }), smooks); SmooksUtil.registerProfileSet( DefaultProfileSet.create("message-target2", new String[] { "profile2", "profile3" }), smooks); // Create CDU configs and target them at the profiles... SmooksResourceConfiguration resourceConfig = new SmooksResourceConfiguration("ccc", "profile1 AND not:profile3", RenameElementTrans.class.getName()); resourceConfig.setParameter("new-name", "xxx"); SmooksUtil.registerResource(resourceConfig, smooks); resourceConfig = new SmooksResourceConfiguration("aaa", "profile2", RenameElementTrans.class.getName()); resourceConfig.setParameter("new-name", "zzz"); SmooksUtil.registerResource(resourceConfig, smooks); // Transform the same message for each useragent... String message = "<aaa><bbb>888</bbb><ccc>999</ccc></aaa>"; ExecutionContext context = smooks.createExecutionContext("message-target1"); CharArrayWriter writer = new CharArrayWriter(); smooks.filterSource(context, new StreamSource(new ByteArrayInputStream(message.getBytes())), new StreamResult(writer)); assertEquals("Unexpected transformation result", "<zzz><bbb>888</bbb><xxx>999</xxx></zzz>", writer.toString()); }