List of usage examples for java.io StringWriter toString
public String toString()
From source file:Main.java
public static String transText(Node doc) throws Exception { TransformerFactory transfactory = TransformerFactory.newInstance(); Transformer transformer = transfactory.newTransformer(); transformer.setOutputProperty("omit-xml-declaration", "yes"); transformer.setOutputProperty("indent", "yes"); Source source = new DOMSource(doc); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); transformer.transform(source, result); return sw.toString(); }
From source file:Main.java
public static String prettyPrint(Node node) { try {//w w w .ja v a 2 s .co m Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); } catch (TransformerException e) { throw new RuntimeException(e); } }
From source file:net.fizzl.redditengine.data.CommentListing.java
/** * Returns a {@link #CommentListing} from an InputStream * //from www . j a v a 2 s . c o m * @param is InputStream containing a comment listing as JSON * @return CommentListing * @throws IOException * @throws JSONException */ public static CommentListing fromInputStream(InputStream is) throws IOException, JSONException { StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); return fromString(writer.toString()); }
From source file:net.prhin.mailman.MailMan.java
private static void printFileContents(BodyPart bodyPart) throws IOException, MessagingException { InputStream is = bodyPart.getInputStream(); StringWriter stringWriter = new StringWriter(); IOUtils.copy(is, stringWriter);/*ww w . ja v a2 s.c o m*/ System.out.println("File Content: " + stringWriter.toString()); }
From source file:at.gv.egovernment.moa.id.auth.builder.RedirectFormBuilder.java
private static String getTemplate() { if (template == null) { try {//from www . jav a 2 s . c om String classpathLocation = "resources/templates/redirectForm.html"; InputStream input = Thread.currentThread().getContextClassLoader() .getResourceAsStream(classpathLocation); StringWriter writer = new StringWriter(); IOUtils.copy(input, writer); template = writer.toString(); } catch (Exception e) { Logger.error("Failed to read template", e); } } return template; }
From source file:Main.java
public static String transText(Node doc) throws Exception { TransformerFactory transfactory = TransformerFactory.newInstance(); Transformer transformer = transfactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); Source source = new DOMSource(doc); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); transformer.transform(source, result); return sw.toString(); }
From source file:Main.java
public static String xmlToString(Document doc) throws Exception { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(doc.getDocumentElement()), new StreamResult(writer)); String result = writer.toString(); System.out.println(result);//from w w w .java 2s . c o m return result; }
From source file:Main.java
/** * Get a string representation of the current stack state of all the active threads. *///from w ww . jav a 2 s.c o m public static String getStackTraces() { StringWriter stringWriter = new StringWriter(5000); printStackTraces(new PrintWriter(stringWriter)); return stringWriter.toString(); }
From source file:Main.java
/** * Check a result.// w w w . j a va2 s . co m * @param result the result * @return the string (trimmed, null if empty) */ public static String checkResult(StringWriter result, boolean checkIndent) { String s = result.toString(); if (s != null) { s = s.trim(); if (checkIndent) { if (s.startsWith(DEFAULT_HEADER + "<")) { s = s.replace(DEFAULT_HEADER, DEFAULT_HEADER + "\r\n"); } } if (s.length() == 0) s = null; } ; return s; }
From source file:org.dthume.maven.xpom.impl.XPOMUtil.java
public static Source modelToSource(final Model model) throws IOException { final StringWriter writer = new StringWriter(); new MavenXpp3Writer().write(writer, model); return new StringSource(writer.toString()); }