Jumbo patch for NET_2_0, mscorlib is now clean
[mono.git] / mcs / class / corlib / System.IO / Stream.cs
old mode 100755 (executable)
new mode 100644 (file)
index e8e8d50..d6e0359
@@ -1,5 +1,5 @@
 //
-// System.IO/Stream.cs
+// System.IO.Stream.cs
 //
 // Authors:
 //   Dietmar Maurer (dietmar@ximian.com)
 // (c) 2004 Novell, Inc. (http://www.novell.com)
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System.Threading;
 using System.Runtime.Remoting.Messaging;
 using System.Runtime.InteropServices;
@@ -17,14 +40,14 @@ using System.Runtime.InteropServices;
 namespace System.IO
 {
        [Serializable]
+       [ComVisible (true)]
+#if NET_2_1
+       public abstract class Stream : IDisposable
+#else
        public abstract class Stream : MarshalByRefObject, IDisposable
+#endif
        {
-               public static readonly Stream Null;
-
-               static Stream ()
-               {
-                       Null = new NullStream ();
-               }
+               public static readonly Stream Null = new NullStream ();
 
                protected Stream ()
                {
@@ -45,6 +68,13 @@ namespace System.IO
                        get;
                }
 
+               [ComVisible (false)]
+               public virtual bool CanTimeout {
+                       get {
+                               return false;
+                       }
+               }
+
                public abstract long Length
                {
                        get;
@@ -57,16 +87,52 @@ namespace System.IO
                }
 
 
+               // 2.0 version of Dispose.
+               public void Dispose ()
+               {
+                       Close ();
+               }
+
+               // 2.0 version of Dispose.
+               protected virtual void Dispose (bool disposing)
+               {
+                       // nothing.
+               }
+
+               //
+               // 2.0 version of Close (): calls Dispose (true)
+               //
                public virtual void Close ()
                {
-                       Flush ();
+                       Dispose (true);
+               }
+
+               [ComVisible (false)]
+               public virtual int ReadTimeout {
+                       get {
+                               throw new InvalidOperationException ("Timeouts are not supported on this stream.");
+                       }
+                       set {
+                               throw new InvalidOperationException ("Timeouts are not supported on this stream.");
+                       }
                }
 
-               void IDisposable.Dispose ()
+               [ComVisible (false)]
+               public virtual int WriteTimeout {
+                       get {
+                               throw new InvalidOperationException ("Timeouts are not supported on this stream.");
+                       }
+                       set {
+                               throw new InvalidOperationException ("Timeouts are not supported on this stream.");
+                       }
+               }
+
+               public static Stream Synchronized (Stream stream)
                {
-                       Close ();
+                       throw new NotImplementedException ();
                }
 
+               [Obsolete ("CreateWaitHandle is due for removal.  Use \"new ManualResetEvent(false)\" instead.")]
                protected virtual WaitHandle CreateWaitHandle()
                {
                        return new ManualResetEvent (false);
@@ -102,7 +168,7 @@ namespace System.IO
                }
 
                public virtual IAsyncResult
-               BeginRead (byte [] buffer, int offset, int count, AsyncCallback cback, object state)
+               BeginRead (byte [] buffer, int offset, int count, AsyncCallback callback, object state)
                {
                        if (!CanRead)
                                throw new NotSupportedException ("This stream does not support reading");
@@ -123,16 +189,16 @@ namespace System.IO
                                result.SetComplete (e, 0);
                        }
 
-                       if (cback != null)
-                               cback (result);
+                       if (callback != null)
+                               callback (result);
 
                        return result;
                }
 
-               delegate void WriteDelegate (byte [] buffer, int offset, int count);
+//             delegate void WriteDelegate (byte [] buffer, int offset, int count);
 
                public virtual IAsyncResult
-               BeginWrite (byte [] buffer, int offset, int count, AsyncCallback cback, object state)
+               BeginWrite (byte [] buffer, int offset, int count, AsyncCallback callback, object state)
                {
                        if (!CanWrite)
                                throw new NotSupportedException ("This stream does not support writing");
@@ -153,20 +219,20 @@ namespace System.IO
                                result.SetComplete (e);
                        }
 
-                       if (cback != null)
-                               cback.BeginInvoke (result, null, null);
+                       if (callback != null)
+                               callback.BeginInvoke (result, null, null);
 
                        return result;
                }
                
-               public virtual int EndRead (IAsyncResult async_result)
+               public virtual int EndRead (IAsyncResult asyncResult)
                {
-                       if (async_result == null)
-                               throw new ArgumentNullException ("async_result");
+                       if (asyncResult == null)
+                               throw new ArgumentNullException ("asyncResult");
 
-                       StreamAsyncResult result = async_result as StreamAsyncResult;
+                       StreamAsyncResult result = asyncResult as StreamAsyncResult;
                        if (result == null || result.NBytes == -1)
-                               throw new ArgumentException ("Invalid IAsyncResult", "async_result");
+                               throw new ArgumentException ("Invalid IAsyncResult", "asyncResult");
 
                        if (result.Done)
                                throw new InvalidOperationException ("EndRead already called.");
@@ -178,14 +244,14 @@ namespace System.IO
                        return result.NBytes;
                }
 
-               public virtual void EndWrite (IAsyncResult async_result)
+               public virtual void EndWrite (IAsyncResult asyncResult)
                {
-                       if (async_result == null)
-                               throw new ArgumentNullException ("async_result");
+                       if (asyncResult == null)
+                               throw new ArgumentNullException ("asyncResult");
 
-                       StreamAsyncResult result = async_result as StreamAsyncResult;
+                       StreamAsyncResult result = asyncResult as StreamAsyncResult;
                        if (result == null || result.NBytes != -1)
-                               throw new ArgumentException ("Invalid IAsyncResult", "async_result");
+                               throw new ArgumentException ("Invalid IAsyncResult", "asyncResult");
 
                        if (result.Done)
                                throw new InvalidOperationException ("EndWrite already called.");
@@ -239,9 +305,7 @@ namespace System.IO
                {
                }
 
-               public override int Read (byte[] buffer,
-                                         int offset,
-                                         int count)
+               public override int Read (byte[] buffer, int offset, int count)
                {
                        return 0;
                }
@@ -251,8 +315,7 @@ namespace System.IO
                        return -1;
                }
 
-               public override long Seek (long offset,
-                                          SeekOrigin origin)
+               public override long Seek (long offset, SeekOrigin origin)
                {
                        return 0;
                }
@@ -261,9 +324,7 @@ namespace System.IO
                {
                }
 
-               public override void Write (byte[] buffer,
-                                           int offset,
-                                           int count)
+               public override void Write (byte[] buffer, int offset, int count)
                {
                }