List of usage examples for java.io Writer toString
public String toString()
From source file:info.magnolia.freemarker.FreemarkerUtil.java
/** * Uses the class to create the templates name and passes the object under the name 'this'. * Uses "html" as template filename extension. * Only used in AbstractSimpleSearchList and VersionsList. *//*from w w w . j a va2 s. c om*/ public static String process(Class<?> klass, Object thisObj) { final Writer writer = new StringWriter(); process(klass, thisObj, writer); return writer.toString(); }
From source file:net.svcret.core.util.XMLUtils.java
public static String serialize(Document document, boolean prettyPrint) { Writer writer = new StringWriter(); serialize(document, prettyPrint, writer); return writer.toString(); }
From source file:info.magnolia.freemarker.FreemarkerUtil.java
/** * Same as {@link #process(Object)} but adds the classifier and the extension to the template name. *///from www.j av a 2 s.com public static String process(Object thisObj, String classifier, String ext) { final Writer writer = new StringWriter(); process(thisObj, classifier, ext, writer); return writer.toString(); }
From source file:org.artifactory.common.wicket.util.JavaScriptUtils.java
public static String jsParam(Object parameter) { Writer writer = new StringWriter(); try {//from w ww . j a va 2 s.c om JsonGenerator generator = JacksonFactory.createJsonGenerator(writer); generator.writeObject(parameter); return writer.toString(); } catch (IOException e) { throw new RuntimeException("Could not write js param '" + parameter + "'.", e); } finally { IOUtils.closeQuietly(writer); } }
From source file:Main.java
/** * Write node to a string./*from w ww .j a v a 2 s . co m*/ * * @param node * the node to write * @return string * @throws TransformerException * if write failed */ public static String toString(Node node) throws TransformerException { DOMSource source = new DOMSource(node); Writer w = new StringWriter(); StreamResult result = new StreamResult(w); transformers.get().transform(source, result); return w.toString(); }
From source file:com.netsteadfast.greenstep.util.TemplateUtils.java
private static String processTemplate(String resource, Map<String, Object> params) throws Exception { StringTemplateLoader templateLoader = new StringTemplateLoader(); templateLoader.putTemplate("sysTemplate", resource); Configuration cfg = new Configuration(Configuration.VERSION_2_3_21); cfg.setTemplateLoader(templateLoader); Template template = cfg.getTemplate("sysTemplate", Constants.BASE_ENCODING); Writer out = new StringWriter(); template.process(params, out);//from w ww . ja v a 2s . c o m return out.toString(); }
From source file:com.netsteadfast.greenstep.util.TemplateUtils.java
/** * ???? template ??//from ww w . java 2 s. c o m * * @param name * @param classLoader * @param templateResource * @param parameter * @return * @throws Exception */ public static String processTemplate(String name, ClassLoader classLoader, String templateResource, Map<String, Object> parameter) throws Exception { StringTemplateLoader templateLoader = new StringTemplateLoader(); templateLoader.putTemplate("resourceTemplate", getResourceSrc(classLoader, templateResource)); Configuration cfg = new Configuration(Configuration.VERSION_2_3_21); cfg.setTemplateLoader(templateLoader); Template template = cfg.getTemplate("resourceTemplate", Constants.BASE_ENCODING); Writer out = new StringWriter(); template.process(parameter, out); return out.toString(); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.XStreamTools.java
public static String toXML(Object object) throws IOException { Writer out = new StringWriter(); out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); XStream xStream = getXStream();//from w w w .ja v a2s. c o m xStream.toXML(object, out); IOUtils.closeQuietly(out); return out.toString(); }
From source file:org.apache.synapse.FaultHandler.java
/** * Get the stack trace into a String//from ww w .ja v a 2 s.co m * @param aThrowable * @return the stack trace as a string */ public static String getStackTrace(Throwable aThrowable) { final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); aThrowable.printStackTrace(printWriter); return result.toString(); }
From source file:Main.java
public static InputStream createInputStream(Element element) throws IOException { byte[] ret = null; try {/* w ww . j a v a 2 s . c o m*/ TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); DOMSource source = new DOMSource(element); Writer writer = new StringWriter(); Result result = new StreamResult(writer); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(source, result); ret = writer.toString().getBytes("UTF-8"); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (TransformerFactoryConfigurationError e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } return new ByteArrayInputStream(ret); }