2002-09-13 Nick Drochak <ndrochak@gol.com>
[mono.git] / mcs / class / corlib / System / Console.cs
1 //
2 // System.Console.cs
3 //
4 // Author:
5 //   Dietmar Maurer (dietmar@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System.IO;
11 using System.Text;
12
13 namespace System {
14
15         public sealed class Console {
16
17                 private static TextWriter stdout;
18                 private static TextWriter stderr;
19                 private static TextReader stdin;
20
21                 static Console ()
22                 {
23                         stderr = new StreamWriter (OpenStandardError (), Encoding.UnixConsoleEncoding);
24                         ((StreamWriter)stderr).AutoFlush = true;
25                         stdout = new StreamWriter (OpenStandardOutput (), Encoding.UnixConsoleEncoding);
26                         ((StreamWriter)stdout).AutoFlush = true;
27                         stdin  = new StreamReader (OpenStandardInput (), Encoding.UnixConsoleEncoding);
28                 }
29
30                 private Console () {}
31                 
32                 public static TextWriter Error
33                 {
34                         get {
35                                 return stderr;
36                         }
37                 }
38
39                 public static TextWriter Out
40                 {
41                         get {
42                                 return stdout;
43                         }
44                 }
45
46                 public static TextReader In
47                 {
48                         get {
49                                 return stdin;
50                         }
51                 }
52
53                 public static Stream OpenStandardError ()
54                 {
55                         return OpenStandardError (0);
56                 }
57                 
58                 public static Stream OpenStandardError (int bufferSize)
59                 {
60                         return new FileStream (MonoIO.ConsoleError,
61                                                FileAccess.Write,
62                                                false,  bufferSize);
63                 }
64
65                 public static Stream OpenStandardInput ()
66                 {
67                         return OpenStandardInput (0);
68                 }
69                 
70                 public static Stream OpenStandardInput (int bufferSize)
71                 {
72                         return new FileStream (MonoIO.ConsoleInput,
73                                                FileAccess.Read,
74                                                false,  bufferSize);
75                 }
76
77                 public static Stream OpenStandardOutput ()
78                 {
79                         return OpenStandardOutput (0);
80                 }
81                 
82                 public static Stream OpenStandardOutput (int bufferSize)
83                 {
84                         return new FileStream (MonoIO.ConsoleOutput,
85                                                FileAccess.Write,
86                                                false,  bufferSize);
87                 }
88
89                 public static void SetError (TextWriter newError)\r
90                 {
91                         if (newError == null)
92                                 throw new ArgumentNullException ();
93
94                         stderr = newError;
95                 }
96
97                 public static void SetIn (TextReader newIn)\r
98                 {
99                         if (newIn == null)
100                                 throw new ArgumentNullException ();
101
102                         stdin = newIn;
103                 }
104
105                 public static void SetOut (TextWriter newOut)\r
106                 {
107                         if (newOut == null)
108                                 throw new ArgumentNullException ();
109
110                         stdout = newOut;
111                 }
112
113                 public static void Write (bool value)
114                 {
115                         stdout.Write (value);
116                 }
117
118                 public static void Write (char value)
119                 {
120                         stdout.Write (value);
121                 }
122
123                 public static void Write (char[] value)
124                 {
125                         stdout.Write (value);
126                 }
127                 
128                 public static void Write (decimal value)
129                 {
130                         stdout.Write (value);
131                 }
132                 
133                 public static void Write (double value)
134                 {
135                         stdout.Write (value);
136                 }
137
138                 public static void Write (int value)
139                 {
140                         stdout.Write (value);
141                 }
142                 
143                 public static void Write (long value)
144                 {
145                         stdout.Write (value);
146                 }
147                 
148                 public static void Write (object value)
149                 {
150                         stdout.Write (value);
151                 }
152                 
153                 public static void Write (float value)
154                 {
155                         stdout.Write (value);
156                 }
157                 
158                 public static void Write (string value)
159                 {
160                         stdout.Write (value);
161                 }
162                 
163                 [CLSCompliant(false)]
164                 public static void Write (uint value)
165                 {
166                         stdout.Write (value);
167                 }
168                 
169                 [CLSCompliant(false)]
170                 public static void Write (ulong value)
171                 {
172                         stdout.Write (value);
173                 }
174                 
175                 public static void Write (string format, object arg0)
176                 {
177                         stdout.Write (format, arg0);
178                 }
179                 
180                 public static void Write (string format, params object[] arg)
181                 {
182                         stdout.Write (format, arg);
183                 }
184                 
185                 public static void Write (char[] buffer, int index, int count)
186                 {
187                         stdout.Write (buffer, index, count);
188                 }
189                 
190                 public static void Write (string format, object arg0, object arg1)
191                 {
192                         stdout.Write (format, arg0, arg1);
193                 }
194                 
195                 public static void Write (string format, object arg0, object arg1, object arg2 )
196                 {
197                         stdout.Write (format, arg0, arg1, arg2);
198                 }
199                 
200                 public static void WriteLine ()
201                 {
202                         stdout.WriteLine ();
203                 }
204                 
205                 public static void WriteLine (bool value)
206                 {
207                         stdout.Write (value);
208                         stdout.WriteLine();
209                 }
210                 
211                 public static void WriteLine (char value)
212                 {
213                         stdout.Write (value);
214                         stdout.WriteLine();
215                 }
216                 
217                 public static void WriteLine (char[] value)
218                 {
219                         stdout.Write (value);
220                         stdout.WriteLine();
221                 }
222                 
223                 public static void WriteLine (decimal value)
224                 {
225                         stdout.Write (value);
226                         stdout.WriteLine();
227                 }
228                 
229                 public static void WriteLine (double value)
230                 {
231                         stdout.Write (value);
232                         stdout.WriteLine();
233                 }
234                 
235                 public static void WriteLine (int value)
236                 {
237                         stdout.Write (value);
238                         stdout.WriteLine();
239                 }
240                 
241                 public static void WriteLine (long value)
242                 {
243                         stdout.Write (value);
244                         stdout.WriteLine();
245                 }
246                 
247                 public static void WriteLine (object value)
248                 {
249                         stdout.Write (value);
250                         stdout.WriteLine();
251                 }
252                 
253                 public static void WriteLine (float value)
254                 {
255                         stdout.Write (value);
256                         stdout.WriteLine();
257                 }
258                 
259                 public static void WriteLine (string value)
260                 {
261                         stdout.Write (value);
262                         stdout.WriteLine();
263                 }
264                 
265                 [CLSCompliant(false)]
266                 public static void WriteLine (uint value)
267                 {
268                         stdout.Write (value);
269                         stdout.WriteLine();
270                 }
271                 
272                 [CLSCompliant(false)]
273                 public static void WriteLine (ulong value)
274                 {
275                         stdout.Write (value);
276                         stdout.WriteLine();
277                 }
278                 
279                 public static void WriteLine (string format, object arg0)
280                 {
281                         stdout.Write (format, arg0);
282                         stdout.WriteLine();
283                 }
284                 
285                 public static void WriteLine (string format, params object[] arg)
286                 {
287                         stdout.Write (format, arg);
288                         stdout.WriteLine();
289                 }
290                 
291                 public static void WriteLine (char[] buffer, int index, int count)
292                 {
293                         stdout.Write (buffer, index, count);
294                         stdout.WriteLine();
295                 }
296                 
297                 public static void WriteLine (string format, object arg0, object arg1)
298                 {
299                         stdout.Write (format, arg0, arg1);
300                         stdout.WriteLine();
301                 }
302                 
303                 public static void WriteLine (string format, object arg0, object arg1, object arg2)
304                 {
305                         stdout.Write (format, arg0, arg1, arg2);
306                         stdout.WriteLine();
307                 }
308
309                 public static int Read ()
310                 {
311                         return stdin.Read ();
312                 }
313                 
314                 public static string ReadLine ()
315                 {
316                         return stdin.ReadLine ();
317                 }
318                 
319         }
320 }