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.meschbach.psi.util.rest.JAXBEntityBuilder.java

public HttpEntity buildEntity() throws PSIException {
    try {//from   www . java2 s . c  o  m
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JAXB.marshal(target, baos);
        return new StringEntity(baos.toString());
    } catch (Exception e) {
        throw new PSIException("Unable to marshall object " + target + "via JAXB", e);
    }
}

From source file:bamons.process.monitoring.service.listener.EmailMonitoringNotifier.java

private String formatExceptionMessage(Throwable exception) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    exception.printStackTrace(new PrintStream(baos));
    return baos.toString();
}

From source file:ch.windmobile.server.socialmodel.mogodb.HeavyLoadTest.java

public void beforeTest() {
    Mongo mongo = null;//  w  ww .  j  a v a  2s  . c  o m
    try {
        mongo = new Mongo();
        DB db = mongo.getDB(MongoDBConstants.DATABASE_NAME);
        InputStream is = getClass().getResourceAsStream("/init-script.js");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        FileCopyUtils.copy(is, out);
        String code = out.toString();
        Logger.getLogger("WindoMobile").info("Create test database");
        Object result = db.doEval(code);
        Logger.getLogger("WindoMobile").info("Result : " + result.toString());

    } catch (Exception e) {
        Logger.getLogger("WindoMobile").log(Level.SEVERE, "Error : " + e.getMessage());
        e.printStackTrace();
    } finally {
        if (mongo != null) {
            mongo.close();
        }
    }
}

From source file:com.ettrema.httpclient.ReportMethod.java

public Document getResponseAsDocument(HttpClient client) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Utils.executeHttpWithStatus(client, this, out);
    String xml = out.toString();
    try {//from w  ww  .  j  a va 2 s . c om
        Document document = RespUtils.getJDomDocument(new ByteArrayInputStream(xml.getBytes()));
        return document;
    } catch (JDOMException ex) {
        throw new RuntimeException(xml, ex);
    }
}

From source file:eu.trentorise.smartcampus.permissionprovider.controller.CASController.java

private static String generateSuccess(User user, boolean isNew) throws Exception {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    ServiceResponseType value = factory.createServiceResponseType();

    AuthenticationSuccessType success = factory.createAuthenticationSuccessType();
    success.setUser("" + user.getId());
    AttributesType attrs = factory.createAttributesType();
    attrs.setIsFromNewLogin(isNew);/*  ww  w.jav a  2s . c o m*/
    attrs.getAny().add(createElement("name", user.getName()));
    attrs.getAny().add(createElement("surname", user.getSurname()));
    if (user.getAttributeEntities() != null) {
        for (Attribute a : user.getAttributeEntities()) {
            attrs.getAny().add(createElement(a.getKey(), a.getValue()));
        }
    }
    success.setAttributes(attrs);
    value.setAuthenticationSuccess(success);

    JAXBElement<ServiceResponseType> createServiceResponse = factory.createServiceResponse(value);

    JAXB.marshal(createServiceResponse, os);
    return os.toString();
}

From source file:org.energyos.espi.common.domain.BatchListMarshallerTest.java

public String newXML() {
    BatchList batchList = new BatchList();
    batchList.getResources().add("foo");
    batchList.getResources().add("bar");

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    jaxb2Marshaller.marshal(batchList, new StreamResult(os));
    return os.toString();
}

From source file:com.cloudbees.jenkins.support.api.FileContentTest.java

@Test
public void truncation() throws Exception {
    File f = tmp.newFile();/*from  w  ww . ja  v  a2 s . c om*/
    FileUtils.writeStringToFile(f, "hello world\n");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new FileContent("-", f).writeTo(baos);
    assertEquals("hello world\n", baos.toString());
    baos.reset();
    new FileContent("-", f, 10).writeTo(baos);
    assertEquals("hello worl", baos.toString());
    baos.reset();
    new FileContent("-", f, 20).writeTo(baos);
    assertEquals("hello world\n", baos.toString());
}

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

public void subscribe(Folder f) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("token", token);
    params.put("folder", f.getName());
    Document doc = null;/*from   w  w  w .j a  v  a2  s  .c o m*/
    try {
        doc = getFolderAsXML(f);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DOMUtils.serialise(doc, out);
        params.put("xmlfolder", out.toString());
        executeVoid(params);

        if (logger.isInfoEnabled()) {
            logger.info("folder subscribed !");
        }

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

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

public void unsubscribe(Folder f) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("token", token);
    params.put("folder", f.getName());
    Document doc = null;/*from  w  ww . j a  va  2  s .co  m*/
    try {
        doc = getFolderAsXML(f);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DOMUtils.serialise(doc, out);
        params.put("xmlfolder", out.toString());
        executeVoid(params);

        if (logger.isInfoEnabled()) {
            logger.info("folder unsubscribed !");
        }

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

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

public void createFolder(Folder f) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("token", token);
    params.put("folder", f.getName());

    Document doc = null;/*from w ww. ja  va2 s .com*/
    try {
        doc = getFolderAsXML(f);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DOMUtils.serialise(doc, out);
        params.put("xmlfolder", out.toString());
        executeVoid(params);

        if (logger.isInfoEnabled()) {
            logger.info("folder created !");
        }

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