{
}
+ 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);
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];
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 ();
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 != '=')
return c;
}
}
- throw new InvalidOperationException ();
}
public Encoding ActualEncoding {