Example usage for java.io OutputStream toString

List of usage examples for java.io OutputStream toString

Introduction

In this page you can find the example usage for java.io OutputStream toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.insilico.titan.Utils.java

public void exportGraphML(TitanGraph graph) {
    try {/* w  w w. j  av  a 2  s .c om*/
        OutputStream out = new ByteArrayOutputStream();
        GraphMLWriter writer = new GraphMLWriter(graph);
        //writer.setVertexKeyTypes(vertexKeyTypes);
        //writer.setEdgeKeyTypes(edgeKeyTypes);
        writer.outputGraph(out);
        System.out.println(out.toString());
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:org.duracloud.stitch.stream.MultiContentInputStreamTest.java

@Test
public void testReadWithListener() throws Exception {
    String text = createReadMocks();
    contentItems.stream().forEach(x -> {
        listener.contentIdRead(x.getContentId());
        EasyMock.expectLastCall().once();
    });//from w w w  .j a v  a  2 s .  c o  m
    replayMocks();

    OutputStream out = new ByteArrayOutputStream();
    multiStream = new MultiContentInputStream(dataSource, contentItems, listener);
    IOUtils.copy(multiStream, out);
    Assert.assertEquals(text, out.toString());
    out.close();
}

From source file:org.sventon.diff.DiffProducerTest.java

@Test
public void testDoNormalDiff() throws Exception {
    final String leftString = "[.ShellClassInfo]" + NL + "IconIndex=-238" + NL + "[DeleteOnCopy]" + NL
            + "Owner=Jesper" + NL + "Owner=Patrik&Jesper" + NL + "Personalized=14" + NL
            + "PersonalizedName=Mina videoklipp" + NL;

    final String rightString = "[.ShellClassInfo]" + NL + "IconIndex=-2388" + NL + "[DeleteOnCopy]" + NL
            + "Owner=Jesper" + NL + "Owner=Patrik&Jesper" + NL + "Personalized=14" + NL
            + "PersonalizedName=Mina videoklipp" + NL + "OneMore=true" + NL + "OneMore=1" + NL + "OneMore=2"
            + NL + "OneMore=3" + NL + NL;

    final String result = "2c2" + NL + "<IconIndex=-2388" + NL + "---" + NL + ">IconIndex=-238" + NL + "8a8,12"
            + NL + ">OneMore=true" + NL + ">OneMore=1" + NL + ">OneMore=2" + NL + ">OneMore=3" + NL + ">" + NL;

    final InputStream left = IOUtils.toInputStream(leftString);
    final InputStream right = IOUtils.toInputStream(rightString);

    final DiffProducer diffProducer = new DiffProducer(left, right, null);
    final OutputStream output = new ByteArrayOutputStream();
    diffProducer.doNormalDiff(output);/*from w w w  .  ja v  a 2s.c om*/
    assertEquals(result, output.toString());

    final Iterator<DiffSegment> actions = DiffResultParser.parseNormalDiffResult(result).iterator();

    DiffSegment action = actions.next();
    assertSame(DiffAction.CHANGED, action.getAction());
    assertEquals(2, action.getLineIntervalStart(LEFT));
    assertEquals(2, action.getLineIntervalEnd(LEFT));
    assertEquals(2, action.getLineIntervalStart(RIGHT));
    assertEquals(2, action.getLineIntervalEnd(RIGHT));
    assertEquals("DiffSegment: CHANGED, left: 2-2, right: 2-2", action.toString());
    action = actions.next();
    assertSame(DiffAction.ADDED, action.getAction());
    assertEquals(8, action.getLineIntervalStart(LEFT));
    assertEquals(8, action.getLineIntervalEnd(LEFT));
    assertEquals(8, action.getLineIntervalStart(RIGHT));
    assertEquals(12, action.getLineIntervalEnd(RIGHT));
    assertEquals("DiffSegment: ADDED, left: 8-8, right: 8-12", action.toString());
}

From source file:org.apache.synapse.commons.json.JsonUtilTest.java

public void testWriteAsJson() throws AxisFault, XMLStreamException {
    OMElement omElement = AXIOMUtil.stringToOM("<name>WSO2</name>");
    OutputStream outputStream = new ByteArrayOutputStream();
    JsonUtil.writeAsJson(omElement, outputStream);
    assertEquals("Invalid payload received", "{\"name\":\"WSO2\"}", outputStream.toString());
}

From source file:org.sventon.diff.DiffProducerTest.java

@Test
public void testDoNormalDiffII() throws Exception {
    final String leftString = "/**" + NL + " * $Author$" + NL + " * $Revision$" + NL + " * $Date:$" + NL + " */"
            + NL + "Test1" + NL + "Another test!" + NL + "More!" + NL + "Even more!" + NL;

    final String rightString = "/**" + NL + " * $Id$" + NL + " * $LastChangedDate$" + NL + " * $Date$" + NL
            + " * $LastChangedRevision$" + NL + " * $Revision$" + NL + " * $Rev$" + NL + " * $LastChangedBy$"
            + NL + " * $Author$" + NL + " * $HeadURL$" + NL + " * $URL$" + NL + " * $Id$" + NL + " */" + NL
            + "Test1" + NL + "Another test!" + NL + "More!" + NL + "Even more!" + NL + NL
            + "public String getRev {" + NL + " return \"$Rev$\";" + NL + NL + "}" + NL;

    final String result = "2,8d2" + NL + "< * $Id$" + NL + "< * $LastChangedDate$" + NL + "< * $Date$" + NL
            + "< * $LastChangedRevision$" + NL + "< * $Revision$" + NL + "< * $Rev$" + NL
            + "< * $LastChangedBy$" + NL + "3,4c10,12" + NL + "< * $Revision$" + NL + "< * $Date:$" + NL + "---"
            + NL + "> * $HeadURL$" + NL + "> * $URL$" + NL + "> * $Id$" + NL + "18,22d10" + NL + "<" + NL
            + "<public String getRev {" + NL + "< return \"$Rev$\";" + NL + "<" + NL + "<}" + NL;

    final InputStream left = IOUtils.toInputStream(leftString);
    final InputStream right = IOUtils.toInputStream(rightString);

    final DiffProducer diffProducer = new DiffProducer(right, left, null);
    final OutputStream output = new ByteArrayOutputStream();
    diffProducer.doNormalDiff(output);/*from   w w  w. java  2  s.c om*/
    assertEquals(result, output.toString());

    final Iterator<DiffSegment> actions = DiffResultParser.parseNormalDiffResult(result).iterator();

    DiffSegment action = actions.next();
    assertSame(DiffAction.DELETED, action.getAction());
    assertEquals(2, action.getLineIntervalStart(LEFT));
    assertEquals(8, action.getLineIntervalEnd(LEFT));
    assertEquals(2, action.getLineIntervalStart(RIGHT));
    assertEquals(2, action.getLineIntervalEnd(RIGHT));
    assertEquals("DiffSegment: DELETED, left: 2-8, right: 2-2", action.toString());
    action = actions.next();
    assertSame(DiffAction.CHANGED, action.getAction());
    assertEquals(3, action.getLineIntervalStart(LEFT));
    assertEquals(4, action.getLineIntervalEnd(LEFT));
    assertEquals(10, action.getLineIntervalStart(RIGHT));
    assertEquals(12, action.getLineIntervalEnd(RIGHT));
    assertEquals("DiffSegment: CHANGED, left: 3-4, right: 10-12", action.toString());
    action = actions.next();
    assertSame(DiffAction.DELETED, action.getAction());
    assertEquals(18, action.getLineIntervalStart(LEFT));
    assertEquals(22, action.getLineIntervalEnd(LEFT));
    assertEquals(10, action.getLineIntervalStart(RIGHT));
    assertEquals(10, action.getLineIntervalEnd(RIGHT));
    assertEquals("DiffSegment: DELETED, left: 18-22, right: 10-10", action.toString());
}

From source file:org.drools.camel.component.cxf.CxfSoapTestWithLookup.java

public void testCxfSoapSessionLookup() throws Exception {

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body.addBodyElement(payloadName);/*from   w w  w  .ja v a 2 s . c  om*/

    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd += "      <org.drools.springframework.Person2>\n";
    cmd += "         <name>salaboy</name>\n";
    cmd += "         <age>27</age>\n";
    cmd += "      </org.drools.springframework.Person2>\n";
    cmd += "   </insert>\n";
    cmd += "   <fire-all-rules/>\n";
    cmd += "</batch-execution>\n";

    body.addTextNode(cmd);

    Object object = this.context.createProducerTemplate().requestBody("direct://http", soapMessage);

    OutputStream out = new ByteArrayOutputStream();
    out = new ByteArrayOutputStream();
    soapMessage = (SOAPMessage) object;
    soapMessage.writeTo(out);
    String response = out.toString();
    assertTrue(response.contains("fact-handle identifier=\"salaboy\""));

    SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage();
    SOAPBody body2 = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName2 = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body2.addBodyElement(payloadName2);

    String cmd2 = "";
    cmd2 += "<batch-execution lookup=\"ksession2\">\n";
    cmd2 += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd2 += "      <org.drools.springframework.Person3>\n";
    cmd2 += "         <name>salaboy</name>\n";
    cmd2 += "         <age>27</age>\n";
    cmd2 += "      </org.drools.springframework.Person3>\n";
    cmd2 += "   </insert>\n";
    cmd2 += "   <fire-all-rules/>\n";
    cmd2 += "</batch-execution>\n";

    body2.addTextNode(cmd2);

    Object object2 = this.context.createProducerTemplate().requestBody("direct://http", soapMessage2);

    OutputStream out2 = new ByteArrayOutputStream();
    out2 = new ByteArrayOutputStream();
    soapMessage2 = (SOAPMessage) object2;
    soapMessage2.writeTo(out2);
    String response2 = out2.toString();
    assertTrue(response2.contains("fact-handle identifier=\"salaboy\""));

}

From source file:org.kie.camel.component.cxf.CxfSoapTestWithLookup.java

public void testCxfSoapSessionLookup() throws Exception {

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body.addBodyElement(payloadName);/*www .  j  ava 2 s .co  m*/

    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd += "      <org.kie.springframework.Person2>\n";
    cmd += "         <name>salaboy</name>\n";
    cmd += "         <age>27</age>\n";
    cmd += "      </org.kie.springframework.Person2>\n";
    cmd += "   </insert>\n";
    cmd += "   <fire-all-rules/>\n";
    cmd += "</batch-execution>\n";

    body.addTextNode(cmd);

    Object object = this.context.createProducerTemplate().requestBody("direct://http", soapMessage);

    OutputStream out = new ByteArrayOutputStream();
    out = new ByteArrayOutputStream();
    soapMessage = (SOAPMessage) object;
    soapMessage.writeTo(out);
    String response = out.toString();
    assertTrue(response.contains("fact-handle identifier=\"salaboy\""));

    SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage();
    SOAPBody body2 = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName2 = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body2.addBodyElement(payloadName2);

    String cmd2 = "";
    cmd2 += "<batch-execution lookup=\"ksession2\">\n";
    cmd2 += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd2 += "      <org.kie.springframework.Person3>\n";
    cmd2 += "         <name>salaboy</name>\n";
    cmd2 += "         <age>27</age>\n";
    cmd2 += "      </org.kie.springframework.Person3>\n";
    cmd2 += "   </insert>\n";
    cmd2 += "   <fire-all-rules/>\n";
    cmd2 += "</batch-execution>\n";

    body2.addTextNode(cmd2);

    Object object2 = this.context.createProducerTemplate().requestBody("direct://http", soapMessage2);

    OutputStream out2 = new ByteArrayOutputStream();
    out2 = new ByteArrayOutputStream();
    soapMessage2 = (SOAPMessage) object2;
    soapMessage2.writeTo(out2);
    String response2 = out2.toString();
    assertTrue(response2.contains("fact-handle identifier=\"salaboy\""));

}

From source file:com.metamx.datatypes.mmx.WriteNewLinesTest.java

@Test
public void testSimpleDeserialization() throws Exception {
    List<MmxAuctionSummary> auctionList = Arrays.asList(sampleAuction1, sampleAuction2);
    final String separator = "\n";

    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    final OutputStream outStream = new ByteArrayOutputStream();

    for (MmxAuctionSummary auction : auctionList) {
        outStream.write(objectMapper.writeValueAsBytes(auction));
        outStream.write(separator.getBytes());
    }//w  ww. ja v a  2  s .  c  o m

    Assert.assertEquals(outputString, outStream.toString());
}

From source file:org.apache.marmotta.platform.core.services.templating.TemplatingServiceImpl.java

@Override
public String process(String name, Map<String, Object> data) throws IOException, TemplateException {
    OutputStream os = new ByteArrayOutputStream();
    Writer writer = new BufferedWriter(new OutputStreamWriter(os));
    process(name, data, writer);/*from w ww  . j  av a 2 s  . c om*/
    return os.toString();
}

From source file:org.apache.wiki.util.CryptoUtilTest.java

public void testCommandLineHash() throws Exception {
    // Save old printstream
    PrintStream oldOut = System.out;

    // Swallow System out and get command output
    OutputStream out = new ByteArrayOutputStream();
    System.setOut(new PrintStream(out));
    CryptoUtil.main(new String[] { "--hash", "password" });
    String output = new String(out.toString());

    // Restore old printstream
    System.setOut(oldOut);//from w ww. jav a  2s.com

    // Run our tests
    assertTrue(output.startsWith("{SSHA}"));
}