2004-12-03 Lluis Sanchez Gual <lluis@novell.com>
[mono.git] / mcs / class / corlib / System.IO / StreamWriter.cs
index 117ab7f5d60d3956726125d94fccec22526b9832..1799d74e6e6046a8d97c1724770f12a8761a5b63 100644 (file)
@@ -137,12 +137,16 @@ namespace System.IO {
                        get {\r
                                return iflush;\r
                        }\r
-                       set {\r
-                               if (DisposedAlready)\r
-                                       throw new ObjectDisposedException("StreamWriter");\r
-                               iflush = value;\r
-                       }\r
-               }\r
+                       set {
+                               if (DisposedAlready)
+                                       throw new ObjectDisposedException("StreamWriter");
+                               iflush = value;
+
+                               if (iflush) {
+                                       Flush ();
+                               }
+                       }
+               }
 \r
                public virtual Stream BaseStream {\r
                        get {\r
@@ -245,6 +249,28 @@ namespace System.IO {
                                index += todo;\r
                                decode_pos += todo;\r
                        }\r
+               }
+               
+               void LowLevelWrite (string s)
+               {
+                       int count = s.Length;
+                       int index = 0;
+                       while (count > 0) {
+                               int todo = decode_buf.Length - decode_pos;
+                               if (todo == 0) {
+                                       Decode ();
+                                       todo = decode_buf.Length;
+                               }
+                               if (todo > count)
+                                       todo = count;
+                               
+                               for (int i = 0; i < todo; i ++)
+                                       decode_buf [i + decode_pos] = s [i + index];
+                               
+                               count -= todo;
+                               index += todo;
+                               decode_pos += todo;
+                       }
                }\r
 \r
                public override void Write (char value)\r
@@ -278,7 +304,8 @@ namespace System.IO {
                                throw new ObjectDisposedException("StreamWriter");\r
 \r
                        if (value != null)\r
-                               LowLevelWrite (value.ToCharArray (), 0, value.Length);\r
+                               LowLevelWrite (value);
+                       \r
                        if (iflush)\r
                                Flush ();\r
                }\r