New tests.
[mono.git] / mcs / class / System.XML / System.Xml / XmlInputStream.cs
index 74df8f7180b0797b3c5a40aaab5c54c5f445d9de..44932ebeb40beca10c54f34e1d8876a676ed99c6 100644 (file)
@@ -51,11 +51,29 @@ namespace System.Xml
                {
                }
 
+               static XmlException invalidDataException = new XmlException ("invalid data.");
+
                public override void Close ()
                {
                        this.input.Close ();
                }
 
+               public override int Read ([In, Out] char[] dest_buffer, int index, int count)
+               {
+                       try {
+                               return base.Read (dest_buffer, index, count);
+                       }
+#if NET_1_1
+                       catch (System.ArgumentException) {
+                               throw invalidDataException;
+                       }
+#else
+                       catch (System.Text.DecoderFallbackException) {
+                               throw invalidDataException;
+                       }
+#endif
+               }
+
                protected override void Dispose (bool disposing)
                {
                        base.Dispose (disposing);
@@ -341,6 +359,19 @@ namespace System.Xml
                        Initialize (stream);
                }
 
+               static string GetStringFromBytes (byte [] bytes, int index, int count)
+               {
+#if MOONLIGHT
+                       char [] chars = new char [count];
+                       for (int i = index; i < count; i++)
+                               chars [i] = (char) bytes [i];
+
+                       return new string (chars);
+#else
+                       return Encoding.ASCII.GetString (bytes, index, count);
+#endif
+               }
+
                private void Initialize (Stream stream)
                {
                        buffer = new byte [64];
@@ -387,7 +418,7 @@ namespace System.Xml
                                break;
                        case '<':
                                // try to get encoding name from XMLDecl.
-                               if (bufLength >= 5 && Encoding.ASCII.GetString (buffer, 1, 4) == "?xml") {
+                               if (bufLength >= 5 && GetStringFromBytes (buffer, 1, 4) == "?xml") {
                                        bufPos += 4;
                                        c = SkipWhitespace ();
 
@@ -405,7 +436,7 @@ namespace System.Xml
 
                                        if (c == 'e') {
                                                int remaining = bufLength - bufPos;
-                                               if (remaining >= 7 && Encoding.ASCII.GetString(buffer, bufPos, 7) == "ncoding") {
+                                               if (remaining >= 7 && GetStringFromBytes (buffer, bufPos, 7) == "ncoding") {
                                                        bufPos += 7;
                                                        c = SkipWhitespace();
                                                        if (c != '=')
@@ -476,7 +507,6 @@ namespace System.Xml
                                        return c;
                                }
                        }
-                       throw new InvalidOperationException ();
                }
 
                public Encoding ActualEncoding {