Package com.thoughtworks.xstream.io

Examples of com.thoughtworks.xstream.io.HierarchicalStreamWriter


     * encoding
     */
    protected String marshall(Session session, ObjectMessage objectMessage) throws JMSException {
        Serializable object = objectMessage.getObject();
        StringWriter buffer = new StringWriter();
        HierarchicalStreamWriter out;
        if (streamDriver != null) {
          out = streamDriver.createWriter(buffer);
        } else {
          out = new PrettyPrintWriter(buffer);
        }
View Full Code Here


  // Marshalling

  @Override
  protected void marshalDomNode(Object graph, Node node) throws XmlMappingException {
    HierarchicalStreamWriter streamWriter;
    if (node instanceof Document) {
      streamWriter = new DomWriter((Document) node);
    }
    else if (node instanceof Element) {
      streamWriter = new DomWriter((Element) node, node.getOwnerDocument(), new XmlFriendlyReplacer());
View Full Code Here

    protected HierarchicalStreamReader createReader(String xml) throws Exception {
        // Transmogrify XML input into binary format.
        HierarchicalStreamReader xmlReader = new XppReader(new StringReader(xml));

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        HierarchicalStreamWriter binaryWriter = new BinaryStreamWriter(buffer);
        copier.copy(xmlReader, binaryWriter);

        return new BinaryStreamReader(new ByteArrayInputStream(buffer.toByteArray()));
    }
View Full Code Here

    public void testHandlesMoreThan256Ids() {
        int count = 500;

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        HierarchicalStreamWriter binaryWriter = new BinaryStreamWriter(buffer);
        binaryWriter.startNode("root");
        for (int i = 0; i < count; i++) {
            binaryWriter.startNode("node" + i);
            binaryWriter.endNode();
        }
        for (int i = 0; i < count; i++) {
            binaryWriter.startNode("node" + i);
            binaryWriter.endNode();
        }
        binaryWriter.endNode();

        HierarchicalStreamReader binaryReader
                = new BinaryStreamReader(new ByteArrayInputStream(buffer.toByteArray()));
        assertEquals("root", binaryReader.getNodeName());
        for (int i = 0; i < count; i++) {
View Full Code Here

    // factory method - overriding base class.
    protected HierarchicalStreamReader createReader(String xml) throws Exception {
        HierarchicalStreamReader sourceReader = new XppReader(new StringReader(xml));

        StringWriter buffer = new StringWriter();
        HierarchicalStreamWriter destinationWriter = new CompactWriter(buffer);

        copier.copy(sourceReader, destinationWriter);

        return new XppReader(new StringReader(buffer.toString()));
    }
View Full Code Here

        String input = "<root><empty1/><empty2></empty2><not-empty>blah</not-empty></root>";
        String expected = "<root><empty1/><empty2/><not-empty>blah</not-empty></root>";
        HierarchicalStreamReader sourceReader = new XppReader(new StringReader(input));

        StringWriter buffer = new StringWriter();
        HierarchicalStreamWriter destinationWriter = new CompactWriter(buffer);

        copier.copy(sourceReader, destinationWriter);

        assertEquals(expected, buffer.toString());
    }
View Full Code Here

    protected void setUp() throws Exception {
        super.setUp();
        pathTracker = new PathTracker();
        out = new StringWriter();
        HierarchicalStreamWriter originalWriter = new CompactWriter(out);

        writer = new PathTrackingWriter(originalWriter, pathTracker);
    }
View Full Code Here

    public void testReadAndWriteMultipleObjectsInOneStream() {
        xstream.alias("person", Person.class);
        StringWriter buffer = new StringWriter();

        // serialize
        HierarchicalStreamWriter writer = new PrettyPrintWriter(buffer);
        writer.startNode("people");
        xstream.marshal(new Person("Postman", "Pat"), writer);
        xstream.marshal(new Person("Bob", "Builder"), writer);
        xstream.marshal(new Person("Tinky", "Winky"), writer);
        writer.endNode();

        assertEquals(""
            + "<people>\n"
            + "  <person>\n"
            + "    <firstName>Postman</firstName>\n"
View Full Code Here

     * afterwards and in case of an exception.
     *
     * @throws XStreamException if the object cannot be serialized
     */
    public void toXML(Object obj, Writer out) {
        HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out);
        try {
            marshal(obj, writer);
        } finally {
            writer.flush();
        }
    }
View Full Code Here

     * will be flushed afterwards and in case of an exception.
     *
     * @throws XStreamException if the object cannot be serialized
     */
    public void toXML(Object obj, OutputStream out) {
        HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out);
        try {
            marshal(obj, writer);
        } finally {
            writer.flush();
        }
    }
View Full Code Here

TOP

Related Classes of com.thoughtworks.xstream.io.HierarchicalStreamWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.