List of usage examples for java.io ByteArrayOutputStream toString
public synchronized String toString()
From source file:org.atomserver.testutils.client.MockRequestContext.java
public void setPropertiesAsText(Properties props) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); props.store(out, null);// w ww. j a v a2 s .c o m setContentAsText(out.toString()); }
From source file:org.atomserver.testutils.client.MockRequestContext.java
public void setPropertiesAsEntry(Properties props) throws IOException { Entry entry = context.getAbdera().getFactory().newEntry(); ByteArrayOutputStream out = new ByteArrayOutputStream(); props.store(out, null);//from w w w. j av a 2 s .c om entry.setContent(out.toString()); setContent(entry); }
From source file:net.officefloor.tutorial.servletmigration.ExampleHttpServletTest.java
/** * Ensure {@link ExampleHttpServlet} servicing request. *//*from www . j ava 2 s. c o m*/ // START SNIPPET: tutorial public void testExampleHttpServlet() throws Exception { // Start WoOF (with Servlet extension on class path) WoofOfficeFloorSource.start(); // Undertake the request to be serviced by Servlet HttpGet request = new HttpGet("http://localhost:7878/example"); HttpResponse response = this.client.execute(request); assertEquals("Ensure request successful", 200, response.getStatusLine().getStatusCode()); // Ensure response entity is as expected ByteArrayOutputStream buffer = new ByteArrayOutputStream(); response.getEntity().writeTo(buffer); assertEquals("Incorrect response entity", "SERVLET", buffer.toString()); }
From source file:com.bluexml.side.form.utils.DOMUtil.java
/** * Serializes a document to a string with the given indentation feature. * // ww w .j a v a2 s . c o m * @param doc * the document to serialize * @return the document's content as a string */ public static String convertDocument2String(Document doc, boolean indent) { StringBuilder stringBuilder = null; try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); OutputFormat outputformat = new OutputFormat(); outputformat.setEncoding("UTF-8"); outputformat.setIndenting(indent); outputformat.setPreserveSpace(false); outputformat.setOmitXMLDeclaration(true); outputformat.setOmitDocumentType(true); XMLSerializer serializer = new XMLSerializer(); serializer.setOutputFormat(outputformat); serializer.setOutputByteStream(stream); serializer.asDOMSerializer(); serializer.serialize(doc.getDocumentElement()); stringBuilder = new StringBuilder(stream.toString()); } catch (Exception e) { e.printStackTrace(); return null; } return stringBuilder.toString(); }
From source file:fr.aliasource.webmail.server.proxy.client.http.SendMessageMethod.java
public SendResponse sendMessage(ClientMessage cm, ReplyInfo ri, SendParameters sp) { SendResponse ret = new SendResponse(); Map<String, String> params = new HashMap<String, String>(); params.put("token", token); if (ri != null) { params.put("folder", ri.getOrigFolder().getName()); params.put("uid", String.valueOf(ri.getId().getMessageId())); }// w w w.ja va 2 s . c o m if (sp != null) { params.putAll(createMapParamsFromSendParameters(sp)); } Document doc = null; try { doc = getMessageAsXML(cm, sp); if (logger.isDebugEnabled()) { DOMUtils.logDom(doc); } ByteArrayOutputStream out = new ByteArrayOutputStream(); DOMUtils.serialise(doc, out); params.put("message", out.toString()); doc = execute(params); if (logger.isInfoEnabled()) { logger.info("[" + token + "] message sent."); } if (doc.getDocumentElement().getNodeName().equals("error")) { ret.setReason(DOMUtils.getElementText(doc.getDocumentElement(), "reason")); } } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage(), e); } return ret; }
From source file:net.officefloor.tutorial.woofservletwebapplication.ExampleIT.java
private void assertRequest(String uri, String expectedContent) throws IOException { // Undertake the request HttpGet request = new HttpGet("http://localhost:18080" + uri); HttpResponse response = this.client.execute(request); assertEquals("Request should be successful: " + uri, 200, response.getStatusLine().getStatusCode()); // Ensure content is as expected ByteArrayOutputStream buffer = new ByteArrayOutputStream(); response.getEntity().writeTo(buffer); assertEquals("Incorrect response entity", expectedContent, buffer.toString()); }
From source file:org.energyos.espi.common.domain.UsagePointMarshallerTests.java
private String newXML() throws DatatypeConfigurationException { ByteArrayOutputStream os = new ByteArrayOutputStream(); atomMarshaller.marshal(EspiFactory.newUsagePoint(), new StreamResult(os)); return os.toString(); }
From source file:net.officefloor.tutorial.woofservletdependencyinjection.ExampleIT.java
public void testTemplate() throws IOException { // Undertake the request HttpGet request = new HttpGet("http://localhost:18181/test/template.woof"); HttpResponse response = this.client.execute(request); assertEquals("Request should be successful", 200, response.getStatusLine().getStatusCode()); // Ensure content is as expected ByteArrayOutputStream buffer = new ByteArrayOutputStream(); response.getEntity().writeTo(buffer); assertEquals("Incorrect response entity", "<html><body>MESSAGE</body></html>", buffer.toString()); }
From source file:net.bpelunit.framework.model.test.wire.OutgoingMessage.java
public String getMessageAsString() { ByteArrayOutputStream out = new ByteArrayOutputStream(); try {// w w w.ja v a 2s .com message.writeTo(out); return out.toString(); } catch (SOAPException e) { return ""; } catch (IOException e) { return ""; } catch (NullPointerException e) { return ""; } finally { IOUtils.closeQuietly(out); } }
From source file:net.jsign.pe.PEFileTest.java
public void testPrintInfo() throws Exception { PEFile file = new PEFile(new File("target/test-classes/wineyes.exe")); ByteArrayOutputStream out = new ByteArrayOutputStream(); file.printInfo(out);/*from www . j a va 2s. co m*/ assertNotNull(out.toString()); assertFalse(out.toString().isEmpty()); System.out.println(out); }