namespace System.IO {
[Serializable]
+#if NET_2_0
+ [ComVisible (true)]
+#endif
public class StreamReader : TextReader {
const int DefaultBufferSize = 1024;
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);
}
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;
}
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;
}
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;
index += cch;
count -= cch;
chars_read += cch;
+ if (mayBlock)
+ break;
}
return chars_read;
}