+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
pushback = new Stack<int>();
}
+ public PushbackReader (Stream stream) : base (stream, true)
+ {
+ pushback = new Stack<int>();
+ }
+
public override void Close ()
{
pushback.Clear ();
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;
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)
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)
{
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]);
- }
}
}