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)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Runtime.InteropServices;
\r
35 namespace System.IO {
\r
38 public abstract class TextReader : MarshalByRefObject, IDisposable {
\r
40 protected TextReader() { }
\r
42 public static readonly TextReader Null;
\r
44 public virtual void Close()
\r
49 void System.IDisposable.Dispose()
\r
54 protected virtual void Dispose( bool disposing )
\r
59 public virtual int Peek()
\r
64 public virtual int Read()
\r
70 public virtual int Read ([In, Out] char[] buffer, int index, int count)
\r
74 for (i = 0; i < count; i++) {
\r
75 if ((c = Read ()) == -1)
\r
77 buffer [index + i] = (char)c;
\r
83 public virtual int ReadBlock ([In, Out] char [] buffer, int index, int count)
\r
85 int total_read_count = 0;
\r
86 int current_read_count = 0;
\r
89 current_read_count = Read (buffer, index, count);
\r
90 index += current_read_count;
\r
91 total_read_count += current_read_count;
\r
92 count -= current_read_count;
\r
93 } while (current_read_count != 0 && count > 0);
\r
95 return total_read_count;
\r
98 public virtual string ReadLine()
\r
100 return String.Empty;
\r
103 public virtual string ReadToEnd()
\r
105 return String.Empty;
\r
108 public static TextReader Synchronized (TextReader reader)
\r
110 if (reader == null)
\r
111 throw new ArgumentNullException ("reader is null");
\r
112 if (reader is SynchronizedReader)
\r
115 return new SynchronizedReader (reader);
\r
120 // Synchronized Reader implementation, used internally.
\r
123 internal class SynchronizedReader : TextReader {
\r
126 public SynchronizedReader (TextReader reader)
\r
128 this.reader = reader;
\r
131 public override void Close ()
\r
138 public override int Peek ()
\r
141 return reader.Peek ();
\r
145 public override int ReadBlock (char [] buffer, int index, int count)
\r
148 return reader.ReadBlock (buffer, index, count);
\r
152 public override string ReadLine ()
\r
155 return reader.ReadLine ();
\r
159 public override string ReadToEnd ()
\r
162 return reader.ReadToEnd ();
\r
165 #region Read Methods
\r
166 public override int Read ()
\r
169 return reader.Read ();
\r
173 public override int Read (char [] buffer, int index, int count)
\r
176 return reader.Read (buffer, index, count);
\r