**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / System.IO / UnexceptionalStreamReader.cs
blob7c527459204643fdc01d15d91445a72f610a920b
1 //
2 // System.IO.UnexceptionalStreamReader.cs
3 //
4 // Authors:
5 // Dietmar Maurer (dietmar@ximian.com)
6 // Miguel de Icaza (miguel@ximian.com)
7 // Dick Porter (dick@ximian.com)
8 //
9 // (C) Ximian, Inc. http://www.ximian.com
10 // Copyright (C) 2004 Novell (http://www.novell.com)
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
23 //
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
26 //
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 // This is a wrapper around StreamReader used by System.Console that
38 // catches IOException so that graphical applications don't suddenly
39 // get IO errors when their terminal vanishes. See
40 // UnexceptionalStreamWriter too.
42 using System;
43 using System.Text;
44 using System.Runtime.InteropServices;
46 namespace System.IO {
47 internal class UnexceptionalStreamReader : StreamReader {
48 public UnexceptionalStreamReader(Stream stream)
49 : base (stream)
53 public UnexceptionalStreamReader(Stream stream, bool detect_encoding_from_bytemarks)
54 : base (stream, detect_encoding_from_bytemarks)
58 public UnexceptionalStreamReader(Stream stream, Encoding encoding)
59 : base (stream, encoding)
63 public UnexceptionalStreamReader(Stream stream, Encoding encoding, bool detect_encoding_from_bytemarks)
64 : base (stream, encoding, detect_encoding_from_bytemarks)
68 public UnexceptionalStreamReader(Stream stream, Encoding encoding, bool detect_encoding_from_bytemarks, int buffer_size)
69 : base (stream, encoding, detect_encoding_from_bytemarks, buffer_size)
73 public UnexceptionalStreamReader(string path)
74 : base (path)
78 public UnexceptionalStreamReader(string path, bool detect_encoding_from_bytemarks)
79 : base (path, detect_encoding_from_bytemarks)
83 public UnexceptionalStreamReader(string path, Encoding encoding)
84 : base (path, encoding)
88 public UnexceptionalStreamReader(string path, Encoding encoding, bool detect_encoding_from_bytemarks)
89 : base (path, encoding, detect_encoding_from_bytemarks)
93 public UnexceptionalStreamReader(string path, Encoding encoding, bool detect_encoding_from_bytemarks, int buffer_size)
94 : base (path, encoding, detect_encoding_from_bytemarks, buffer_size)
98 public override int Peek ()
100 try {
101 return(base.Peek ());
102 } catch (IOException) {
105 return(-1);
108 public override int Read ()
110 try {
111 return(base.Read ());
112 } catch (IOException) {
115 return(-1);
118 public override int Read ([In, Out] char[] dest_buffer,
119 int index, int count)
121 try {
122 return(base.Read (dest_buffer, index, count));
123 } catch (IOException) {
126 return(0);
129 public override string ReadLine()
131 try {
132 return(base.ReadLine ());
133 } catch (IOException) {
136 return(null);
139 public override string ReadToEnd()
141 try {
142 return(base.ReadToEnd ());
143 } catch (IOException) {
146 return(null);