2 // System.IO.TextReader
\r
5 // Marcin Szczepanski (marcins@zipworld.com.au)
\r
6 // Miguel de Icaza (miguel@gnome.org)
\r
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
\r
12 // Permission is hereby granted, free of charge, to any person obtaining
\r
13 // a copy of this software and associated documentation files (the
\r
14 // "Software"), to deal in the Software without restriction, including
\r
15 // without limitation the rights to use, copy, modify, merge, publish,
\r
16 // distribute, sublicense, and/or sell copies of the Software, and to
\r
17 // permit persons to whom the Software is furnished to do so, subject to
\r
18 // the following conditions:
\r
20 // The above copyright notice and this permission notice shall be
\r
21 // included in all copies or substantial portions of the Software.
\r
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
33 using System.Runtime.InteropServices;
\r
35 namespace System.IO {
\r
41 public abstract class TextReader : MarshalByRefObject, IDisposable {
\r
43 protected TextReader() { }
\r
45 public static readonly TextReader Null;
\r
47 public virtual void Close()
\r
53 public void Dispose ()
\r
55 void System.IDisposable.Dispose()
\r
61 protected virtual void Dispose (bool disposing)
\r
64 // If we are explicitly disposed, we can avoid finalization.
\r
65 GC.SuppressFinalize (this);
\r
70 public virtual int Peek()
\r
75 public virtual int Read()
\r
81 public virtual int Read ([In, Out] char[] buffer, int index, int count)
\r
85 for (i = 0; i < count; i++) {
\r
86 if ((c = Read ()) == -1)
\r
88 buffer [index + i] = (char)c;
\r
94 public virtual int ReadBlock ([In, Out] char [] buffer, int index, int count)
\r
96 int total_read_count = 0;
\r
97 int current_read_count = 0;
\r
100 current_read_count = Read (buffer, index, count);
\r
101 index += current_read_count;
\r
102 total_read_count += current_read_count;
\r
103 count -= current_read_count;
\r
104 } while (current_read_count != 0 && count > 0);
\r
106 return total_read_count;
\r
109 public virtual string ReadLine()
\r
111 return String.Empty;
\r
114 public virtual string ReadToEnd()
\r
116 return String.Empty;
\r
119 public static TextReader Synchronized (TextReader reader)
\r
121 if (reader == null)
\r
122 throw new ArgumentNullException ("reader is null");
\r
123 if (reader is SynchronizedReader)
\r
126 return new SynchronizedReader (reader);
\r
131 // Synchronized Reader implementation, used internally.
\r
134 internal class SynchronizedReader : TextReader {
\r
137 public SynchronizedReader (TextReader reader)
\r
139 this.reader = reader;
\r
142 public override void Close ()
\r
149 public override int Peek ()
\r
152 return reader.Peek ();
\r
156 public override int ReadBlock (char [] buffer, int index, int count)
\r
159 return reader.ReadBlock (buffer, index, count);
\r
163 public override string ReadLine ()
\r
166 return reader.ReadLine ();
\r
170 public override string ReadToEnd ()
\r
173 return reader.ReadToEnd ();
\r
176 #region Read Methods
\r
177 public override int Read ()
\r
180 return reader.Read ();
\r
184 public override int Read (char [] buffer, int index, int count)
\r
187 return reader.Read (buffer, index, count);
\r