List of usage examples for java.io StringWriter toString
public String toString()
From source file:architecture.common.license.io.LicenseWriter.java
public static String encode(License license, int columns, LicenseSigner signer) throws IOException { LicenseWriter lw = new LicenseWriter(license, signer); StringWriter writer = new StringWriter(); lw.write(writer, columns);/* ww w . java 2 s. com*/ return writer.toString(); }
From source file:Main.java
/** * Convert an <code>org.w3c.dom.Node</code> to a <code>String</code> without including any XML header information. * //from w w w.j a v a 2s.c o m * @param node the <code>org.w3c.dom.Node</code> to convert to a String. * @return a <code>String</code> representing the the <code>org.w3c.dom.Node</code> * @throws TransformerException if there was a problem with the conversion */ public static String nodeToString(Node node) throws TransformerException { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter stringWriter = new StringWriter(); transformer.transform(new DOMSource(node), new StreamResult(stringWriter)); return stringWriter.toString(); }
From source file:io.fares.junit.soapui.outside.test.SoapUIMockRunnerTest.java
public static String testMockService(String endpoint) throws MalformedURLException, IOException { HttpURLConnection con = (HttpURLConnection) new URL(endpoint).openConnection(); con.setRequestMethod("POST"); con.addRequestProperty("Accept", "application/soap+xml"); con.addRequestProperty("Content-Type", "application/soap+xml"); con.setDoOutput(true);// ww w. j a v a 2s. co m con.getOutputStream().write( "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"><soap:Header/><soap:Body><GetWeather xmlns=\"http://www.webserviceX.NET\"><CityName>Brisbane</CityName></GetWeather></soap:Body></soap:Envelope>" .getBytes("UTF-8")); InputStream is = con.getInputStream(); StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); String rs = writer.toString(); LOG.fine(rs); return rs; }
From source file:Main.java
public static String inputStreamToString(InputStream inputStream) throws IOException { StringWriter sw = new StringWriter(); int c;/* w w w. j a v a2 s . c o m*/ InputStream in = inputStream; while ((c = in.read()) != -1) { sw.write(c); } return sw.toString(); }
From source file:Main.java
public static String toString(InputStream input) throws IOException { StringWriter sw = new StringWriter(); copy(input, sw);/*from www. ja va 2s . co m*/ return sw.toString(); }
From source file:Main.java
public static String render(String name, byte[] xmldata) { StringWriter writer = new StringWriter(512); render(name, xmldata, writer);/* w w w .j ava 2s . c o m*/ return writer.toString(); }
From source file:voldemort.utils.VoldemortIOUtils.java
public static String toString(final InputStream input, final String encoding, final long limit) throws IOException { StringWriter sw = new StringWriter(); copy(input, sw, encoding, limit);//from w w w . j av a 2s. c o m return sw.toString(); }
From source file:net.sf.sripathi.ws.mock.util.WebServiceutil.java
/** * Invokes the web service using SAAJ API. * //from w w w . j a va 2 s . c om * @param request soap request string. * @param url end point URL. * @param user user name for authentication. * @param password password for authentication. * * @return response soap string. */ public static String callWebService(String request, String url, String user, String password) { if (request == null) request = ""; try { SOAPConnection conn = SOAPConnectionFactory.newInstance().createConnection(); MimeHeaders hd = new MimeHeaders(); hd.addHeader("Content-Type", "text/xml"); if (StringUtil.isValid(user) && StringUtil.isValid(password)) { String authorization = new String(Base64.encodeBase64((user + ":" + password).getBytes())); hd.addHeader("Authorization", "Basic " + authorization); } SOAPMessage msg = MessageFactory.newInstance().createMessage(hd, new ByteArrayInputStream(request.getBytes())); SOAPMessage resp = conn.call(msg, url); ByteArrayOutputStream baos = new ByteArrayOutputStream(); resp.writeTo(baos); return new String(baos.toByteArray()); } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); return sw.toString(); } }
From source file:Main.java
public static String getAsText(Node n) { try {//w w w .j a va 2 s.c o m Transformer t = TransformerFactory.newInstance().newTransformer(); StringWriter out = new StringWriter(); t.transform(new javax.xml.transform.dom.DOMSource(n), new javax.xml.transform.stream.StreamResult(out)); return out.toString(); } catch (Throwable t) { t.printStackTrace(); return null; } }
From source file:Main.java
public static String toString(Element element) { try {/*from ww w . ja v a2 s .c om*/ Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StringWriter buffer = new StringWriter(); transformer.transform(new DOMSource(element), new StreamResult(buffer)); return buffer.toString(); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerFactoryConfigurationError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } return null; }