Example usage for java.io StringWriter toString

List of usage examples for java.io StringWriter toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Return the buffer's current value as a string.

Usage

From source file:com.redhat.refarch.microservices.trigger.service.TriggerService.java

private static URIBuilder getUriBuilder(Object... path) {

    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme("http");
    uriBuilder.setHost("gateway-service");
    uriBuilder.setPort(9091);/*  www . j a  va 2 s.  c om*/

    StringWriter stringWriter = new StringWriter();
    for (Object part : path) {
        stringWriter.append('/').append(String.valueOf(part));
    }
    uriBuilder.setPath(stringWriter.toString());
    return uriBuilder;
}

From source file:Main.java

public static String parseObjToXmlString(Object obj) {
    if (obj == null) {
        return noResult;
    }/*from w w w  .j a  v a2s. c om*/
    StringWriter sw = new StringWriter();
    JAXBContext jAXBContext;
    Marshaller marshaller;
    try {
        jAXBContext = JAXBContext.newInstance(obj.getClass());
        marshaller = jAXBContext.createMarshaller();
        marshaller.marshal(obj, sw);
        return sw.toString();
    } catch (JAXBException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return noResult;
}

From source file:Main.java

/**
 *
 * @param obj// ww  w. ja  v a 2s  .  c  om
 * @return
 * @throws JAXBException
 */
public static String serializeToString(Object obj) throws JAXBException {
    java.io.StringWriter sw = new StringWriter();
    final Marshaller m = JAXBContext.newInstance(obj.getClass()).createMarshaller();
    m.setProperty(JAXB_FRAGMENT, TRUE);
    m.setProperty(JAXB_FORMATTED_OUTPUT, TRUE);
    m.marshal(obj, sw);
    return sw.toString();
}

From source file:com.redhat.rcm.version.testutil.TestProjectFixture.java

public static void dumpModel(final Model model) throws IOException {
    final StringWriter writer = new StringWriter();
    new MavenXpp3Writer().write(writer, model);

    System.out.println("\n\n" + writer.toString() + "\n\n");
}

From source file:ch.tkuhn.nanobrowser.NanopubElement.java

public static String getTemplate(String name) {
    try {//from   w w  w.  java2 s  .  co m
        String f = "/templates/" + name + ".template.trig";
        InputStream in = TripleStoreAccess.class.getResourceAsStream(f);
        StringWriter writer = new StringWriter();
        IOUtils.copy(in, writer, "UTF-8");
        return writer.toString();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:com.aliyun.odps.ship.common.Util.java

public static String getStack(Exception e) {

    StringWriter errors = new StringWriter();
    PrintWriter w = new PrintWriter(errors);
    e.printStackTrace(w);//from ww w  . j  a va2s.co m
    w.close();
    return errors.toString();
}

From source file:com.streamsets.pipeline.lib.util.CsvUtil.java

public static String csvRecordToString(Record r, CSVFormat csvFormat) throws IOException {
    StringWriter stringWriter = new StringWriter();
    CSVPrinter csvPrinter = new CSVPrinter(stringWriter, csvFormat);
    csvPrinter.printRecord(CsvUtil.fieldToCsv(r.get()));
    csvPrinter.flush();/*from  w ww.  j a  v a 2 s . c om*/
    csvPrinter.close();
    return stringWriter.toString();
}

From source file:Main.java

private static String getStringFromDocument(Node doc) {
    try {/* w  ww.j  a  v  a  2s  . c  o m*/
        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);
        return writer.toString();
    } catch (TransformerException ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static String parseObject2XmlString(Object object) {
    if (object == null) {
        return noResult;
    }// w  w  w .ja v  a  2 s  .com
    StringWriter sw = new StringWriter();
    JAXBContext jAXBContent;
    Marshaller marshaller;
    try {
        jAXBContent = JAXBContext.newInstance(object.getClass());
        marshaller = jAXBContent.createMarshaller();
        marshaller.marshal(object, sw);
        return sw.toString();
    } catch (Exception e) {
        e.printStackTrace();
        return noResult;
    }
}

From source file:Main.java

private static String parseObject2XmlString(Object object) {
    if (object == null) {
        return noResult;
    }//from   w  w w . jav  a  2  s  .c om
    StringWriter sw = new StringWriter();
    JAXBContext jaxbContext;
    Marshaller marshaller;
    try {
        jaxbContext = JAXBContext.newInstance(object.getClass());
        marshaller = jaxbContext.createMarshaller();
        marshaller.marshal(object, sw);
        return sw.toString();
    } catch (JAXBException e) {
        e.printStackTrace();
        return noResult;
    }
}