List of usage examples for java.io StringWriter flush
public void flush()
From source file:Main.java
public static void main(String[] args) { StringWriter sw = new StringWriter(); // create a new sequence String s = "from java2s.com"; // write a string sw.write(s);/* www. j a v a 2s . co m*/ // flush the writer sw.flush(); System.out.println(sw.toString()); }
From source file:Main.java
public static void error(Component parent, Exception e, String title) { StringWriter out = new StringWriter(); e.printStackTrace(new PrintWriter(out)); out.flush(); error(parent, out.getBuffer().toString(), title); }
From source file:Main.java
public static String getStackTrace(Throwable t) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw, true); t.printStackTrace(pw);/*w w w . j a v a 2 s . c om*/ pw.flush(); sw.flush(); return sw.toString(); }
From source file:org.opoo.press.util.LinkUtils.java
public static String renderUrl(String pattern, Map<String, Object> params) { try {/*from w w w . j ava 2 s .co m*/ Configuration configuration = new Configuration(); Template template = new Template("filename", new StringReader(pattern), configuration, "UTF-8"); StringWriter writer = new StringWriter(); template.process(params, writer); writer.flush(); return writer.toString(); } catch (Exception e) { throw new RuntimeException("Render url failed: " + e.getMessage(), e); } }
From source file:edu.unc.lib.dl.util.SOAPUtil.java
public static String getString(SOAPMessage msg) { StringWriter w = new StringWriter(); StreamResult result = new StreamResult(w); print(msg, result);/* w w w .j a v a 2 s . c o m*/ w.flush(); return w.toString(); }
From source file:org.lexgrid.loader.data.DataUtils.java
public static <T extends Property> T deepCloneProperty(T property) throws Exception { StringWriter writer = new StringWriter(); property.marshal(writer);// w w w . j av a 2 s . c o m writer.flush(); String stringProp = writer.toString(); StringReader reader = new StringReader(stringProp); return (T) Unmarshaller.unmarshal(property.getClass(), reader); }
From source file:com.joliciel.csvLearner.utils.LogUtils.java
/** Return the current exception & stack trace as a String. */// ww w . java2s. com public static String getErrorString(Throwable e) { String s = null; try { StringWriter sw = new StringWriter(); PrintWriter ps = new PrintWriter((Writer) sw); e.printStackTrace(ps); sw.flush(); s = sw.toString(); sw.close(); } catch (IOException ioe) { // do nothing! } return s; }
From source file:Main.java
private static String getXmlString(Document document, String tagName) throws ParserConfigurationException, SAXException, IOException, TransformerException { NodeList nodeList = document.getElementsByTagName(tagName); if (nodeList.getLength() < 1) { throw new IllegalArgumentException("no " + tagName + " found"); }//from w w w . jav a 2 s. c o m Node sub = nodeList.item(0); DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document subdoc = db.newDocument(); subdoc.appendChild(sub.cloneNode(true)); TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); DOMSource domSource = new DOMSource(subdoc); StringWriter sw = new StringWriter(); StreamResult xmlResult = new StreamResult(sw); transformer.transform(domSource, xmlResult); sw.flush(); return sw.toString(); }
From source file:Main.java
/** * Serialize XML Node to string/*from ww w . ja v a2 s . c o m*/ * <p> * Note: this method is supposed to be faster than the Transform version but the output control * is limited. If node is Document node, it will output XML PI which sometimes we want to avoid. * * @param doc XML document * @param node Node to be serialized * @param encoding encoding for the output * @return String representation of the Document * @throws IOException */ public static String serializeToStringLS(Document doc, Node node, String encoding) throws IOException { DOMImplementationLS domImpl = (DOMImplementationLS) doc.getImplementation(); LSSerializer lsSerializer = domImpl.createLSSerializer(); LSOutput output = domImpl.createLSOutput(); output.setEncoding(encoding); StringWriter writer = new StringWriter(); output.setCharacterStream(writer); lsSerializer.write(node, output); writer.flush(); return writer.toString(); }
From source file:org.yamj.common.tools.ClassTools.java
/** * Helper method to print the stack trace to the log file * * @param tw//from w w w .j a v a2 s .c om * @return */ public static String getStackTrace(Throwable tw) { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw, true); tw.printStackTrace(pw); pw.flush(); sw.flush(); return sw.toString(); }