in System.ServiceModel.Web/System.Runtime.Serialization.Json:
authorChris Toshok <toshok@novell.com>
Tue, 8 Dec 2009 04:56:29 +0000 (04:56 -0000)
committerChris Toshok <toshok@novell.com>
Tue, 8 Dec 2009 04:56:29 +0000 (04:56 -0000)
2009-12-07  Chris Toshok  <toshok@ximian.com>

* JsonReaderWriterFactory.cs (CreateJsonReader): pass null for the
encoding parameter instead of calling Detect.  The jsonreader's
PushbackReader will autodetect.
(Detect): remove.  a BufferedStream created from an unseekable
stream is itself unseekable, which makes it just as useless.  This
breaks netflix's isostore file parsing.

* JsonReader.cs (PushbackReader): add a ctor which doesn't take an
encoding, for the autodetecting reader case.  for this ctor, pass
true to StreamReader's ctor for detectEncodingFromByteOrderMarks.

svn path=/trunk/mcs/; revision=147829

mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/ChangeLog
mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonReader.cs
mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonReaderWriterFactory.cs

index 5748a92e773d8ff617d600af82a69b433bf490a9..733aaea7cc9b799df876b4180526b1a89b10a491 100644 (file)
@@ -1,3 +1,16 @@
+2009-12-07  Chris Toshok  <toshok@ximian.com>
+
+       * JsonReaderWriterFactory.cs (CreateJsonReader): pass null for the
+       encoding parameter instead of calling Detect.  The jsonreader's
+       PushbackReader will autodetect.
+       (Detect): remove.  a BufferedStream created from an unseekable
+       stream is itself unseekable, which makes it just as useless.  This
+       breaks netflix's isostore file parsing.
+
+       * JsonReader.cs (PushbackReader): add a ctor which doesn't take an
+       encoding, for the autodetecting reader case.  for this ctor, pass
+       true to StreamReader's ctor for detectEncodingFromByteOrderMarks.
+
 2009-12-06  Chris Toshok  <toshok@ximian.com>
 
        * JsonSerializationReader.cs (DeserializeGenericCollection): this
index b6be5a350d41e884cdc36785afda4f53b7aca54c..8e91959b878e613ab37938f55e3f1f6b2514a598 100644 (file)
@@ -43,6 +43,11 @@ namespace System.Runtime.Serialization.Json
                        pushback = new Stack<int>();
                }
 
+               public PushbackReader (Stream stream) : base (stream, true)
+               {
+                       pushback = new Stack<int>();
+               }
+
                public override void Close ()
                {
                        pushback.Clear ();
@@ -154,7 +159,10 @@ namespace System.Runtime.Serialization.Json
 
                public void SetInput (Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
                {
-                       reader = new PushbackReader (stream, encoding ?? Encoding.UTF8);
+                       if (encoding != null)
+                               reader = new PushbackReader (stream, encoding);
+                       else
+                               reader = new PushbackReader (stream);
                        if (quotas == null)
                                throw new ArgumentNullException ("quotas");
                        this.quotas = quotas;
index 08ca6586a734721bc49e8f867263a09e13997479..58084224c311b7be148485e2db7e88d41b0d5f6d 100644 (file)
@@ -43,7 +43,7 @@ namespace System.Runtime.Serialization.Json
 
                public static XmlDictionaryReader CreateJsonReader (byte [] source, int offset, int length, XmlDictionaryReaderQuotas quotas)
                {
-                       return CreateJsonReader (source, offset, length, Detect (source), quotas, null);
+                       return CreateJsonReader (source, offset, length, null, quotas, null);
                }
 
                public static XmlDictionaryReader CreateJsonReader (byte [] source, int offset, int length, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose readerClose)
@@ -53,7 +53,7 @@ namespace System.Runtime.Serialization.Json
 
                public static XmlDictionaryReader CreateJsonReader (Stream source, XmlDictionaryReaderQuotas quotas)
                {
-                       return CreateJsonReader (source, Detect (source), quotas, null);
+                       return CreateJsonReader (source, null, quotas, null);
                }
 
                public static XmlDictionaryReader CreateJsonReader (Stream source, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose readerClose)
@@ -75,35 +75,5 @@ namespace System.Runtime.Serialization.Json
                {
                        return new JsonWriter (stream, encoding, closeOutput);
                }
-
-               static Encoding Detect (int b1, int b2)
-               {
-                       if (b1 != -1 && b2 != -1) {
-                               if (b1 != 0 && b2 == 0)
-                                       return new UnicodeEncoding (false, false, true);
-                               else if (b1 == 0 && b2 != 0)
-                                       return new UnicodeEncoding (true, false, true);
-                       }
-                       return new UTF8Encoding (false, true);
-               }
-
-               static Encoding Detect (Stream source)
-               {
-                       if (source == null)
-                               throw new ArgumentNullException ("source");
-                       Stream stream = source;
-                       if (!stream.CanSeek)
-                               stream = new BufferedStream (source);
-                       Encoding e = Detect (stream.ReadByte(), stream.ReadByte());
-                       stream.Position = 0;
-                       return e;
-               }
-
-               static Encoding Detect (byte[] bytes)
-               {
-                       if (bytes.Length < 2)
-                               return new UTF8Encoding (false, true);
-                       return Detect (bytes[0], bytes[1]);
-               }
        }
 }