From 729745883823b701b69dbbeb4a227ef712047a7a Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Tue, 8 Dec 2009 04:56:29 +0000 Subject: [PATCH] in System.ServiceModel.Web/System.Runtime.Serialization.Json: 2009-12-07 Chris Toshok * 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 --- .../System.Runtime.Serialization.Json/ChangeLog | 13 +++++++++ .../JsonReader.cs | 10 ++++++- .../JsonReaderWriterFactory.cs | 34 ++-------------------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/ChangeLog b/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/ChangeLog index 5748a92e773..733aaea7cc9 100644 --- a/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/ChangeLog +++ b/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/ChangeLog @@ -1,3 +1,16 @@ +2009-12-07 Chris Toshok + + * 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 * JsonSerializationReader.cs (DeserializeGenericCollection): this diff --git a/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonReader.cs b/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonReader.cs index b6be5a350d4..8e91959b878 100644 --- a/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonReader.cs +++ b/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonReader.cs @@ -43,6 +43,11 @@ namespace System.Runtime.Serialization.Json pushback = new Stack(); } + public PushbackReader (Stream stream) : base (stream, true) + { + pushback = new Stack(); + } + 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; diff --git a/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonReaderWriterFactory.cs b/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonReaderWriterFactory.cs index 08ca6586a73..58084224c31 100644 --- a/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonReaderWriterFactory.cs +++ b/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonReaderWriterFactory.cs @@ -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]); - } } } -- 2.11.4.GIT