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.comcast.cmb.test.tools.CNSTestingUtils.java

public static String deleteMessage(CQSControllerServlet cqs, User user, String queueURL, String receiptHandle)
        throws Exception {

    SimpleHttpServletRequest request = new SimpleHttpServletRequest();

    request.setRequestUrl(queueURL);/* w w w.  j ava2 s  . com*/
    Map<String, String[]> params = new HashMap<String, String[]>();

    addParam(params, "Action", "DeleteMessage");
    addParam(params, "AWSAccessKeyId", user.getAccessKey());
    addParam(params, "ReceiptHandle", receiptHandle);

    request.setParameterMap(params);
    SimpleHttpServletResponse response = new SimpleHttpServletResponse();

    OutputStream out = new ByteArrayOutputStream();

    response.setOutputStream(out);

    cqs.doGet(request, response);
    response.getWriter().flush();

    return out.toString();
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static String receiveMessage(CQSControllerServlet cqs, User user, String queueURL,
        String numberOfMessages) throws Exception {

    SimpleHttpServletRequest request = new SimpleHttpServletRequest();

    request.setRequestUrl(queueURL);/*from www. j  a  va 2 s  . c o m*/
    //System.out.println("Queue URL: " + queueURL);
    Map<String, String[]> params = new HashMap<String, String[]>();

    addParam(params, "Action", "ReceiveMessage");
    addParam(params, "AWSAccessKeyId", user.getAccessKey());
    addParam(params, "MaxNumberOfMessages", numberOfMessages);

    request.setParameterMap(params);
    logger.debug("Sending request:" + request.toString());
    SimpleHttpServletResponse response = new SimpleHttpServletResponse();

    OutputStream out = new ByteArrayOutputStream();

    response.setOutputStream(out);

    cqs.doGet(request, response);
    response.getWriter().flush();

    return out.toString();
}

From source file:hu.petabyte.redflags.web.svc.InternalRenderer.java

public String evalView(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model,
        Locale locale, String viewName) throws Exception {
    CustomHttpServletResponse customResponse = new CustomHttpServletResponse(response);
    View view = viewResolver.resolveViewName(viewName, locale);
    if (view != null) {
        view.render(model, request, customResponse);
        OutputStream os = customResponse.getOutputStream();
        return os.toString();
    }// w  w  w  .  j av  a  2 s .com
    throw new Exception("no view found");
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static String addQueue(CQSControllerServlet cqs, User user, String qName) throws Exception {

    SimpleHttpServletRequest request = new SimpleHttpServletRequest();
    request.setRequestUrl(CMBProperties.getInstance().getCQSServiceUrl());
    Map<String, String[]> params = new HashMap<String, String[]>();

    addParam(params, "Action", "CreateQueue");
    addParam(params, "AWSAccessKeyId", user.getAccessKey());
    addParam(params, "QueueName", qName);

    addParam(params, "Attribute.1.Name", "VisibilityTimeout");
    addParam(params, "Attribute.1.Value", "30");
    addParam(params, "Attribute.2.Name", "Policy");
    addParam(params, "Attribute.2.Value", "");
    addParam(params, "Attribute.3.Name", "MaximumMessageSize");
    addParam(params, "Attribute.3.Value", "65536");
    addParam(params, "Attribute.4.Name", "MessageRetentionPeriod");
    addParam(params, "Attribute.4.Value", "600");
    addParam(params, "Attribute.5.Name", "DelaySeconds");
    addParam(params, "Attribute.5.Value", "0");

    request.setParameterMap(params);// w ww  . j a  v  a  2s  .  c o  m
    SimpleHttpServletResponse response = new SimpleHttpServletResponse();

    OutputStream out = new ByteArrayOutputStream();
    response.setOutputStream(out);

    cqs.doGet(request, response);
    response.getWriter().flush();

    return out.toString();
}

From source file:org.ebayopensource.turmeric.eclipse.resources.util.SOAConsumerUtil.java

/**
 * Save props file for consumer./*from ww  w.java 2  s .c  o  m*/
 *
 * @param project the project
 * @param props the props
 * @param monitor the monitor
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws CoreException the core exception
 */
public static void savePropsFileForConsumer(IProject project, final Properties props, IProgressMonitor monitor)
        throws IOException, CoreException {
    final IFile file = SOAConsumerUtil.getConsumerPropertiesFile(project);
    OutputStream output = null;
    try {
        output = new ByteArrayOutputStream();
        props.store(output, SOAProjectConstants.PROPS_COMMENTS);
        WorkspaceUtil.writeToFile(output.toString(), file, monitor);
    } finally {
        IOUtils.closeQuietly(output);
    }
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static String setPermissionForUser(CQSControllerServlet cqs, User user, User user2, String queueURL)
        throws Exception {

    SimpleHttpServletRequest request = new SimpleHttpServletRequest();

    request.setRequestUrl(queueURL);/*from ww  w  .  j  ava2 s  . c om*/
    //System.out.println("Queue URL: " + queueURL);
    Map<String, String[]> params = new HashMap<String, String[]>();

    addParam(params, "Action", "AddPermission");
    addParam(params, "Label", "testLabel");
    addParam(params, "AWSAccessKeyId", user.getAccessKey());
    addParam(params, "AWSAccountId.1", user2.getUserId());
    addParam(params, "ActionName.1", "SendMessage");

    request.setParameterMap(params);
    logger.debug("Sending request:" + request.toString());
    SimpleHttpServletResponse response = new SimpleHttpServletResponse();

    OutputStream out = new ByteArrayOutputStream();

    response.setOutputStream(out);

    cqs.doGet(request, response);
    response.getWriter().flush();
    logger.debug("Add Permissions Response:" + out.toString());
    return out.toString();
}

From source file:petascope.util.XMLUtil.java

/**
 * Serialize a XOM Document.//from   ww w  . ja  v  a 2 s . c o  m
 *
 * @param xomDocument   the XOM Document to be serialized
 * @param noPrettyPrint
 * @throws IOException
 */
public static String serialize(Document xomDocument, boolean noPrettyPrint) throws IOException {
    OutputStream os = new ByteArrayOutputStream();
    serialize(xomDocument, os, noPrettyPrint);
    return os.toString();
}

From source file:org.jboss.pnc.causeway.pncclient.SingletonJsonConversionIT.java

private String convertToJson(Object object) throws IOException {
    OutputStream stream = new ByteArrayOutputStream();
    new ObjectMapper().writeValue(stream, object);
    stream.close();//from ww  w .j a v  a 2 s  .c o  m
    return stream.toString();
}

From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java

public static void deleteallTopics(CNSControllerServlet cns, User user, OutputStream out) {
    //Get all topics

    try {//from   w w w  .j  ava2s. com
        listTopics(cns, user, out, null);
    } catch (Exception e) {
        logger.error("Exception", e);
        assertTrue(false);
    }
    String res = out.toString();
    Vector<String> arns = getArnsFromString(res);

    //Delete all topics
    //System.out.println("Deleting arns size:" + arns.size());

    try {
        for (String arn : arns) {
            //System.out.println("Deleting arn:" + arn);
            deleteTopic(cns, user, out, arn);

        }
    } catch (Exception e) {
        logger.error("Exception", e);
        assertFalse(true);
    }

}

From source file:org.eclipse.om2m.commons.utils.XmlMapper.java

/**
 * Converts a resource Java object into resource XML representation.
 * @param object - resource Java object/*from  ww  w.j  a va  2 s.c  o m*/
 * @return resource XML representation
 */
public String objectToXml(Object object) {

    try {
        Marshaller marshaller = ctx.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        OutputStream outputStream = new ByteArrayOutputStream();
        marshaller.marshal(object, outputStream);

        return outputStream.toString();
    } catch (JAXBException e) {

        LOGGER.error("JAXB unmarshalling error!", e);
        logservice.log(LogService.LOG_ERROR, "JAXB unmarshalling error!");

    }
    return null;
}