Example usage for java.io ByteArrayOutputStream toString

List of usage examples for java.io ByteArrayOutputStream toString

Introduction

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

Prototype

public synchronized String toString() 

Source Link

Document

Converts the buffer's contents into a string decoding bytes using the platform's default character set.

Usage

From source file:com.cloud.utils.ssh.SSHKeysHelper.java

public String getPrivateKey() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    keyPair.writePrivateKey(baos);/*from   w  w  w  . j a v  a 2  s . c  o m*/

    return baos.toString();
}

From source file:net.officefloor.tutorial.gwtapp.GwtAppTest.java

/**
 * Ensure includes GWT script and iframe.
 *///w w w . j a v  a 2  s . com
public void testIncludeGwtAspects() throws Exception {
    try (CloseableHttpClient client = HttpTestUtil.createHttpClient()) {

        // Start server
        WoofOfficeFloorSource.start();

        // Send request for page
        HttpResponse response = client.execute(new HttpGet("http://localhost:7878/template.woof"));

        // Ensure request is successful
        assertEquals("Request should be successful", 200, response.getStatusLine().getStatusCode());

        // Obtain response body
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        response.getEntity().writeTo(buffer);
        String body = buffer.toString();

        // Ensure contains GWT script and iframe
        assertTrue("Should include GWT script", body.contains("src=\"template/template.nocache.js\""));
        assertTrue("Should include GWT iframe", body.contains("<iframe"));

    } finally {
        // Stop the client and server
        WoofOfficeFloorSource.stop();
    }
}

From source file:com.cloud.utils.ssh.SSHKeysHelper.java

public String getPublicKey() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    keyPair.writePublicKey(baos, "");

    return baos.toString();
}

From source file:fr.aliasource.webmail.server.proxy.client.http.StoreMessageMethod.java

public ConversationId storeMessage(Folder dest, ClientMessage cm, SendParameters sp) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("token", token);

    if (sp != null) {
        params.putAll(createMapParamsFromSendParameters(sp));
    }//from ww w  . j  av a2 s  .c o m

    try {
        Document message = getMessageAsXML(cm, sp);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DOMUtils.serialise(message, out);
        params.put("message", out.toString());
        params.put("folder", dest.getName());
        Document doc = execute(params);
        String[] ids = parseConversationIds(doc.getDocumentElement());
        if (ids.length == 1) {
            return new ConversationId(ids[0]);
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}

From source file:fr.aliasource.webmail.server.proxy.client.http.setting.SaveSignatureMethod.java

public void saveSignature(Map<String, String> identities) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("token", token);

    Document doc = null;/*from w  ww.  jav  a2s  .c om*/
    try {
        doc = getSignaturesAsXML(identities);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DOMUtils.serialise(doc, out);
        params.put("xmlsignature", out.toString());
        executeVoid(params);

        if (logger.isInfoEnabled()) {
            logger.info("signature saved !");
        }

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:net.officefloor.tutorial.woofservletjspintegration.JspIT.java

private void assertRequest(String uri, String expectedContent) throws IOException {

    try (CloseableHttpClient client = HttpTestUtil.createHttpClient()) {

        // Undertake the request
        HttpResponse response = client.execute(new HttpGet("http://localhost:18180" + uri));
        assertEquals("Request should be successful: " + uri, 200, response.getStatusLine().getStatusCode());

        // Ensure content is as expected (removing additional white spacing)
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        response.getEntity().writeTo(buffer);
        String html = buffer.toString();
        html = html.replace('\t', ' ');
        html = html.replace('\n', ' ');
        html = html.replace('\r', ' ');
        while (html.contains("  ")) {
            html = html.replace("  ", " ");
        }//from ww w.  j  a v a 2 s .c  o m
        html = html.trim();

        // Ensure response is as expected
        assertEquals("Incorrect response entity", expectedContent, html);

    }
}

From source file:org.springframework.boot.actuate.metrics.ambari.DummyAmbariMetricWriter.java

@Override
protected void doSendMetrics(TimelineMetrics timelineMetrics) {
    try {/*from   w w  w .  j  a  v a 2  s  .com*/
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        objectMapper.writeValue(out, timelineMetrics);
        logger.info("New Metrics: \n" + out.toString());
    } catch (IOException e) {
        logger.error("", e);
    }
}

From source file:org.apache.servicemix.http.HttpAddressingTest.java

public void testOkFromUrl() throws Exception {
    URLConnection connection = new URL("http://localhost:8192/Service/").openConnection();
    connection.setDoOutput(true);/*from  w w  w. jav  a2 s  .  c o  m*/
    connection.setDoInput(true);
    OutputStream os = connection.getOutputStream();
    // Post the request file.
    InputStream fis = getClass().getResourceAsStream("addressing-request.xml");
    FileUtil.copyInputStream(fis, os);
    // Read the response.
    InputStream is = connection.getInputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    FileUtil.copyInputStream(is, baos);
    log.info(baos.toString());
}

From source file:net.bpelunit.framework.control.deploy.ode.ODERequestEntityFactory.java

private void prepareUndeploySOAP(String packageId) throws SOAPException, IOException {
    MessageFactory mFactory = MessageFactory.newInstance();
    SOAPMessage message = mFactory.createMessage();
    SOAPBody body = message.getSOAPBody();

    SOAPElement xmlUndeploy = body.addChildElement(ODE_ELEMENT_UNDEPLOY);
    SOAPElement xmlPackageName = xmlUndeploy.addChildElement(ODE_ELEMENT_PACKAGENAME);
    xmlPackageName.setTextContent(packageId);

    ByteArrayOutputStream b = new ByteArrayOutputStream();
    message.writeTo(b);//from  w ww  .j  a  v a2 s.c  o m
    fContent = b.toString();
}

From source file:aurelienribon.gdxsetupui.LibraryManager.java

private synchronized void registerLibraryDef(String name, ByteArrayOutputStream output) {
    librariesDefs.put(name, new LibraryDef(output.toString()));
}