X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.IO%2FStreamReader.cs;h=70e08f91967a70e2ed9f1fb55ce8af40e325f97d;hb=7c970f8ee1f635da8575bcf58d89c16bb5c2ace1;hp=9102031f2f3ef4bfd276129172d6180c0f990282;hpb=538d3bb80572334c18ae117ea7703406a4a22872;p=mono.git diff --git a/mcs/class/corlib/System.IO/StreamReader.cs b/mcs/class/corlib/System.IO/StreamReader.cs index 9102031f2f3..70e08f91967 100644 --- a/mcs/class/corlib/System.IO/StreamReader.cs +++ b/mcs/class/corlib/System.IO/StreamReader.cs @@ -38,6 +38,9 @@ using System.Runtime.InteropServices; namespace System.IO { [Serializable] +#if NET_2_0 + [ComVisible (true)] +#endif public class StreamReader : TextReader { const int DefaultBufferSize = 1024; @@ -161,12 +164,6 @@ namespace System.IO { if (buffer_size <= 0) throw new ArgumentOutOfRangeException ("buffer_size", "The minimum size of the buffer must be positive"); - string DirName = Path.GetDirectoryName(path); - if (DirName != String.Empty && !Directory.Exists(DirName)) - throw new DirectoryNotFoundException ("Directory '" + DirName + "' not found."); - if (!File.Exists(path)) - throw new FileNotFoundException("File not found.", path); - Stream stream = (Stream) File.OpenRead (path); Initialize (stream, encoding, detect_encoding_from_bytemarks, buffer_size); } @@ -195,7 +192,10 @@ namespace System.IO { do_checks = detect_encoding_from_bytemarks ? 1 : 0; do_checks += (preamble.Length == 0) ? 0 : 2; - decoded_buffer = new char [encoding.GetMaxCharCount (buffer_size)]; + // since GetChars() might add flushed character, it + // should have additional char buffer for extra 1 + // (probably 1 is ok, but might be insufficient. I'm not sure) + decoded_buffer = new char [encoding.GetMaxCharCount (buffer_size) + 1]; decoded_count = 0; pos = 0; } @@ -265,13 +265,15 @@ namespace System.IO { if (count < 2) return 0; - if (input_buffer [0] == 0xfe && input_buffer [1] == 0xff){ - this.encoding = Encoding.BigEndianUnicode; +#if !NET_2_0 + if (input_buffer [0] == 0xff && input_buffer [1] == 0xfe){ + this.encoding = Encoding.Unicode; return 2; } +#endif - if (input_buffer [0] == 0xff && input_buffer [1] == 0xfe){ - this.encoding = Encoding.Unicode; + if (input_buffer [0] == 0xfe && input_buffer [1] == 0xff){ + this.encoding = Encoding.BigEndianUnicode; return 2; } @@ -282,6 +284,33 @@ namespace System.IO { this.encoding = Encoding.UTF8Unmarked; return 3; } + +#if NET_2_0 + if (count < 4) { + if (input_buffer [0] == 0xff && input_buffer [1] == 0xfe && input_buffer [2] != 0) { + this.encoding = Encoding.Unicode; + return 2; + } + return 0; + } + + if (input_buffer [0] == 0 && input_buffer [1] == 0 + && input_buffer [2] == 0xfe && input_buffer [3] == 0xff) + { + this.encoding = Encoding.BigEndianUTF32; + return 4; + } + + if (input_buffer [0] == 0xff && input_buffer [1] == 0xfe) { + if (input_buffer [2] == 0 && input_buffer[3] == 0) { + this.encoding = Encoding.UTF32; + return 4; + } + + this.encoding = Encoding.Unicode; + return 2; + } +#endif } return 0; @@ -375,6 +404,8 @@ namespace System.IO { index += cch; count -= cch; chars_read += cch; + if (mayBlock) + break; } return chars_read; }