[gxml] XParser: Reimplemented create_stream, write_strem methods



commit 27c04242c220abf790001b27b38d1378c4884b95
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Oct 26 14:06:58 2017 -0500

    XParser: Reimplemented create_stream, write_strem methods

 gxml/XParser.vala |   34 +++-------------------------------
 1 files changed, 3 insertions(+), 31 deletions(-)
---
diff --git a/gxml/XParser.vala b/gxml/XParser.vala
index b053020..33bf492 100644
--- a/gxml/XParser.vala
+++ b/gxml/XParser.vala
@@ -53,21 +53,7 @@ public class GXml.XParser : Object, GXml.Parser {
 
   public void write_stream (OutputStream stream,
                             GLib.Cancellable? cancellable = null) throws GLib.Error {
-    var buf = new Xml.Buffer ();
-    tw = new TextWriter.memory (buf);
-    if (_node is DomDocument) tw.start_document ();
-    tw.set_indent (indent);
-    // Root
-    if (_node is DomDocument) {
-      if ((_node as DomDocument).document_element == null)
-        tw.end_document ();
-    }
-    start_node (_node);
-    tw.end_element ();
-    tw.end_document ();
-    tw.flush ();
-    var s = new GLib.StringBuilder ();
-    s.append (buf.content ());
+    var s = dump ();
     var b = new GLib.MemoryInputStream.from_data (s.data, null);
     stream.splice (b, GLib.OutputStreamSpliceFlags.NONE);
     stream.close ();
@@ -112,23 +98,9 @@ public class GXml.XParser : Object, GXml.Parser {
    */
   public InputStream
   create_stream (GLib.Cancellable? cancellable = null) throws GLib.Error {
-    var buf = new Xml.Buffer ();
-    tw = new TextWriter.memory (buf);
-    if (_node is DomDocument) tw.start_document ();
-    tw.set_indent (indent);
-    // Root
-    if (_node is DomDocument) {
-      if ((_node as DomDocument).document_element == null)
-        tw.end_document ();
-    }
-    start_node (_node);
-    tw.end_element ();
-    tw.end_document ();
-    tw.flush ();
-    var s = new GLib.StringBuilder ();
-    s.append (buf.content ());
+    var s = dump ();
     tw = null;
-    return new GLib.MemoryInputStream.from_data ((uint8[]) s.str.dup (), null);
+    return new GLib.MemoryInputStream.from_data (s.data, null);
   }
   /**
    * Creates asynchronically an {@link GLib.InputStream} to write a string representation


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]