public static void SerializeUtf8 (XmlSerializer serializer, Stream stream, object o) { if (serializer == null) throw new ArgumentNullException ("serializer"); if (stream == null) throw new ArgumentNullException ("stream"); if (o == null) throw new ArgumentNullException ("o"); UnclosableStream unclosable_stream = new UnclosableStream (stream); BufferedStream buffered_stream = new BufferedStream (unclosable_stream, 8192); Stopwatch w = new Stopwatch (); w.Start (); XmlTextWriter xml_writer = new XmlTextWriter (buffered_stream, Encoding.UTF8); xml_writer.Formatting = Formatting.Indented; serializer.Serialize (xml_writer, o); // This will flush the stream and release the buffer. // Normally it also closes the underlying stream, // which is why it wraps an UnclosableStream. buffered_stream.Dispose (); w.Stop (); if (Debug) Log.Debug (">>> Serialization of {0}: {1}", o.GetType (), w); }
public static void SerializeUtf8(XmlSerializer serializer, Stream stream, object o) { if (serializer == null) { throw new ArgumentNullException("serializer"); } if (stream == null) { throw new ArgumentNullException("stream"); } if (o == null) { throw new ArgumentNullException("o"); } UnclosableStream unclosable_stream = new UnclosableStream(stream); BufferedStream buffered_stream = new BufferedStream(unclosable_stream, 8192); Stopwatch w = new Stopwatch(); w.Start(); XmlTextWriter xml_writer = new XmlTextWriter(buffered_stream, Encoding.UTF8); xml_writer.Formatting = Formatting.Indented; serializer.Serialize(xml_writer, o); // This will flush the stream and release the buffer. // Normally it also closes the underlying stream, // which is why it wraps an UnclosableStream. buffered_stream.Dispose(); w.Stop(); if (Debug) { Log.Debug(">>> Serialization of {0}: {1}", o.GetType(), w); } }