/** * Serialize and object to a hierarchical data structure (such as XML). * * @throws XStreamException if the object cannot be serialized */ public void marshal(Object obj, HierarchicalStreamWriter writer) { marshal(obj, writer, null); }
public void writeToStream(final Object object) { marshal(object, statefulWriter, dataHolder); }
/** * Marshals the given object with the given XStream into {@link XStreamDOM} and return it. */ public static XStreamDOM from(XStream xs, Object obj) { WriterImpl w = newWriter(); xs.marshal(obj, w); return w.getOutput(); }
String strXML = ""; XStream xs = new XStream(); StringWriter sw = new StringWriter(); xs.marshal(this, new CompactWriter(sw)); strXML = sw.toString();
/** * Marshals the given graph to the given XStream HierarchicalStreamWriter. * Converts exceptions using {@link #convertXStreamException}. */ private void doMarshal(Object graph, HierarchicalStreamWriter streamWriter, @Nullable DataHolder dataHolder) { try { getXStream().marshal(graph, streamWriter, dataHolder); } catch (Exception ex) { throw convertXStreamException(ex, true); } finally { try { streamWriter.flush(); } catch (Exception ex) { logger.debug("Could not flush HierarchicalStreamWriter", ex); } } }
static void writeToXml(Serializable serializable, BufferedOutputStream bufferedOutput) throws IOException { final XStream xstream = createXStream(false); // on wrappe avec un CompactWriter pour gagner 25% en taille de flux (retours chariots) // et donc un peu en performances final CompactWriter writer = new CompactWriter( new OutputStreamWriter(bufferedOutput, XML_CHARSET_NAME)); try { xstream.marshal(serializable, writer); } finally { writer.close(); } }
/** * Serialize an object to the given OutputStream as pretty-printed XML. The OutputStream * 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(); } }
/** * Serialize an object to the given Writer as pretty-printed XML. The Writer will be flushed * 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(); } }
this.startDocument(true); for (Iterator i = source.iterator(); i.hasNext();) { xstream.marshal(i.next(), this);
public static String toXml(final Object o) { final Writer writer = new StringWriter(); XSTREAM_INSTANCE.marshal(o, new CompactWriter(writer)); return writer.toString(); }
/** * Serialize and object to a hierarchical data structure (such as XML). * * @throws XStreamException if the object cannot be serialized */ public void marshal(final Object obj, final HierarchicalStreamWriter writer) { marshal(obj, writer, null); }
/** * Serialize and object to a hierarchical data structure (such as XML). * * @throws XStreamException if the object cannot be serialized */ public void marshal(Object obj, HierarchicalStreamWriter writer) { marshal(obj, writer, null); }
/** * Serialize and object to a hierarchical data structure (such as XML). * * @throws XStreamException if the object cannot be serialized */ public void marshal(Object obj, HierarchicalStreamWriter writer) { marshal(obj, writer, null); }
@Override public <T> String to(T obj) { Writer writer = new StringWriter(); PrettyPrintWriter prettyPrinter = new PrettyPrintWriter(writer); xstream.marshal(obj, prettyPrinter); String xml = writer.toString(); if (LOGGER.isDebugEnabled()) LOGGER.debug("XML Output: " + xml); return xml; }
@Override public void attributeChanged() { XStream xStream = Circuit.getxStream(); try (Writer out = new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.UTF_8)) { out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); xStream.marshal(attributes, new PrettyPrintWriter(out)); } catch (Exception e) { e.printStackTrace(); } }
public static Document writeToDom4JDoc(Object obj) { // dom4JDriver produces a Dom4JXmlWriter, which cannot write mixedContent. // dom4jDriver.setOutputFormat(dom4jOutputFormat); XStream xstream = new XStream(); Document targetDoc = DocumentHelper.createDocument(); //BehaviorDataLoader.initBehaviorXStream(xstream); Dom4JWriter d4jWriter = new Dom4JWriter(targetDoc); xstream.marshal(obj, d4jWriter); return targetDoc; } public static OutputFormat getPrettyDom4jOutputFormat() {
/** * Marshals the given object with the given XStream into {@link XStreamDOM} and return it. */ public static XStreamDOM from(XStream xs, Object obj) { WriterImpl w = newWriter(); xs.marshal(obj, w); return w.getOutput(); }
@Override public void encode(Object object, ContentHandler handler) throws Exception { // prepare xml encoding XStream xstream = buildXStream(); // bind with the content handler SaxWriter writer = new SaxWriter(); writer.setContentHandler(handler); // write out xml xstream.marshal(object, writer); }
public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception { HierarchicalStreamWriter writer = createHierarchicalStreamWriter(exchange, body, stream); try { getXStream(exchange.getContext()).marshal(body, writer); } finally { writer.close(); } }
@SuppressWarnings("resource") private void assertBinarySerialization(final Object root) { // serialize as binary final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); xstream.marshal(root, new BinaryStreamWriter(outputStream)); // deserialize the binary and check it equals the original object. final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Object binaryResult = xstream.unmarshal(new BinaryStreamReader(inputStream)); assertObjectsEqual(root, binaryResult); }