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:Main.java

public static void main(String[] args) throws IOException {

    byte[] bs = { 65, 66, 67, 68, 69, 70, 71, 72 };

    OutputStream os = new ByteArrayOutputStream();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    baos.write(bs);//from w  ww .  j  a v  a2 s  . com

    baos.writeTo(os);

    System.out.println(os.toString());

}

From source file:Main.java

public static void main(String[] args) throws IOException {

    byte[] bs = { 65, 66, 67, 68, 69, 70, 71, 72 };

    OutputStream os = new ByteArrayOutputStream();

    ByteArrayOutputStream baos = new ByteArrayOutputStream(200);

    baos.write(bs);//from  w  ww .  j a va  2s  .co  m

    baos.writeTo(os);

    System.out.println(os.toString());

}

From source file:com.metamx.datatypes.ExampleWriteNewLineJson.java

public static void main(String[] args) throws Exception {
    final MmxAuctionSummary sampleAuction1 = MmxAuctionSummary.builder()
            .timestamp(new DateTime("2014-01-01T00:00:00.000Z")).auctionType(2).build();
    final MmxAuctionSummary sampleAuction2 = MmxAuctionSummary.builder()
            .timestamp(new DateTime("2014-01-01T01:00:00.000Z")).auctionType(1).build();

    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 w w.  ja va2  s  . c o m*/
    System.out.println(outStream.toString());
}

From source file:Main.java

public static String toString(Document doc) throws TransformerException {

    OutputStream result = new ByteArrayOutputStream();

    transfer(doc, result);//from w  w w.  j a  va 2  s .  c  o m

    return result.toString();
}

From source file:org.eclipse.om2m.commons.obix.io.ObixEncoder.java

/**
 * Convert an oBIX java object to its string representation
 * //  w ww.ja  v  a2 s  .  com
 * @param obj
 *            The object to convert
 * @return the String representation of the object
 */
public static String toString(Obj obj) {
    try {
        Marshaller marshaller = ObixMapper.getInstance().getJAXBContext().createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        OutputStream outputStream = new ByteArrayOutputStream();
        marshaller.marshal(obj, outputStream);
        return outputStream.toString();
    } catch (JAXBException e) {
        LOG.error("Error in encoding oBIX object", e);
    }
    return null;
}

From source file:au.org.ecoinformatics.rifcs.RifcsBuilderTest.java

private static String getExpectedText(String filename) throws IOException {
    InputStream is = RifcsBuilder.class.getResourceAsStream(filename);
    OutputStream baos = new ByteArrayOutputStream();
    IOUtils.copy(is, baos);//from w  w  w  . j  a  v  a2s .co  m
    return baos.toString();
}

From source file:org.giavacms.base.common.util.HtmlUtils.java

public static String prettyHtml(String code) {
    if (code == null) {
        code = "";
    }//www .  ja  v  a2s. co m
    Tidy tidy = new Tidy();
    tidy.setXHTML(true);
    tidy.setTidyMark(false);
    tidy.setDocType("omit");
    tidy.setPrintBodyOnly(true);
    tidy.setInputEncoding("UTF-8");
    tidy.setShowErrors(0);
    tidy.setShowWarnings(false);
    tidy.setIndentContent(true);
    // Convert HTML to DOM
    Document htmlDOM = tidy.parseDOM(new ByteArrayInputStream(code.getBytes()), null);
    Node body = htmlDOM.getElementsByTagName("body").item(0);
    // Pretty Print
    OutputStream out = new ByteArrayOutputStream();
    tidy.pprint(body, out);

    return out.toString();
}

From source file:org.grycap.gpf4med.graph.base.visual.GraphvizPrinter.java

public static void print(final Node node) throws IOException {
    try (final Transaction tx = GraphDatabaseHandler.INSTANCE.service().beginTx()) {
        final TraversalDescription td = Traversal.description().depthFirst()
                .relationships(RelTypes.IS, Direction.BOTH).evaluator(Evaluators.all());
        final GraphvizWriter writer = new GraphvizWriter();
        final OutputStream outputStream = new ByteArrayOutputStream();
        writer.emit(outputStream, Walker.crosscut(td.traverse(node).nodes(), RelTypes.IS));
        System.out.println(outputStream.toString());
        tx.success();/*  w  ww .ja va2  s  . c o  m*/
    }
}

From source file:com.bmw.spdxeditor.editors.spdx.SPDXEditorUtility.java

/**
 * Output SPDXDocument RDF model as string.
 * @param document//  ww w .j  ava 2 s.co m
 * @return
 */
public static String saveModelToString(SPDXDocument document) {
    // Save document
    Model spdxFileModel = document.getModel();

    //RDFWriter w = spdxFileModel.getWriter("RDF/XML-ABBREV");
    RDFWriter w = spdxFileModel.getWriter("RDF/XML");
    w.setProperty("attribtueQuoteChar", "'");
    w.setProperty("showXMLDeclaration", "true");
    w.setProperty("tab", "3");

    OutputStream fileOut = new ByteArrayOutputStream();
    w.write(spdxFileModel, fileOut, "");
    return fileOut.toString();
}

From source file:Main.java

static public Document createDocumentFromXMLContent(String docContent) throws SAXException,
        ParserConfigurationException, IOException, TransformerConfigurationException, TransformerException {
    // create builder
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

    // create document
    Document doc = docBuilder.parse(new ByteArrayInputStream(docContent.getBytes()));

    // create transformer to remove spaces
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory
            .newTransformer(new StreamSource("src/test/resources/strip-spaces.xls"));

    // load doc/*from w w w. j  a v a  2  s  .c  om*/
    DOMSource source = new DOMSource(doc);
    OutputStream os = new ByteArrayOutputStream();
    StreamResult result = new StreamResult(os);

    // remove spaces from doc
    transformer.transform(source, result);

    // re-create doc
    return docBuilder.parse(new ByteArrayInputStream(os.toString().getBytes()));
}