* BufferedStream.cs (SetLength): Add checks and throw the
authorDuncan Mak <duncan@mono-cvs.ximian.com>
Wed, 9 Jun 2004 17:10:54 +0000 (17:10 -0000)
committerDuncan Mak <duncan@mono-cvs.ximian.com>
Wed, 9 Jun 2004 17:10:54 +0000 (17:10 -0000)
appropriate Exceptions here instead.

* FileStream.cs (SetLength): Revert part of my last patch, we're
throwing ObjectDisposedException instead of IOException again.

svn path=/trunk/mcs/; revision=29123

mcs/class/corlib/System.IO/BufferedStream.cs
mcs/class/corlib/System.IO/ChangeLog
mcs/class/corlib/System.IO/FileStream.cs

index d70ad125374d8e875aa5279c474bf3ec635a0eb2..c256188821cba6056c9b25768c2d30ef56896d39 100644 (file)
@@ -124,6 +124,16 @@ namespace System.IO {
                public override void SetLength (long value)
                {
                        CheckObjectDisposedException ();
+
+                       if (value < 0)
+                               throw new ArgumentOutOfRangeException ("value must be positive");
+
+                       if (!m_stream.CanWrite && !m_stream.CanSeek)
+                               throw new NotSupportedException ("the stream cannot seek nor write.");
+
+                       if ((m_stream == null) || (!m_stream.CanRead && !m_stream.CanWrite))
+                               throw new IOException ("the stream is not open");
+                       
                        m_stream.SetLength(value);
                        if (Position > value)
                                Position = value;
@@ -250,6 +260,6 @@ namespace System.IO {
                                throw new ObjectDisposedException ("BufferedStream", 
                                        Locale.GetText ("Stream is closed"));
                        }
-               }                       
+               }
        }
 }
index 85639c95b1860740f2e5b4bf906fb94e6d224f46..0ce85c2cbb34c7b7f4f51ea5600e46958582841e 100644 (file)
@@ -1,3 +1,11 @@
+2004-06-09  Duncan Mak  <duncan@ximian.com>
+
+       * BufferedStream.cs (SetLength): Add checks and throw the
+       appropriate Exceptions here instead.
+
+       * FileStream.cs (SetLength): Revert part of my last patch, we're
+       throwing ObjectDisposedException instead of IOException again.
+
 2004-06-09  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * FileStream.cs: re-enabled ignoring broken pipe errors when reading.
index 2466fbf359a49a393c11ec315130f0ee6021ea92..556a634406624a84a85736e45df5ff679bb243bf 100644 (file)
@@ -709,20 +709,17 @@ namespace System.IO
 
                public override void SetLength (long length)
                {
-                       if(CanSeek == false) {
+                       if (handle == MonoIO.InvalidHandle)
+                               throw new ObjectDisposedException ("Stream has been closed");
+
+                       if(CanSeek == false)
                                throw new NotSupportedException("The stream does not support seeking");
-                       }
 
-                       if(CanWrite == false) {
+                       if(CanWrite == false)
                                throw new NotSupportedException("The stream does not support writing");
-                       }
 
-                       if(length < 0) {
+                       if(length < 0)
                                throw new ArgumentOutOfRangeException("Length is less than 0");
-                       }
-
-                       if (handle == MonoIO.InvalidHandle)
-                               throw new IOException ("Stream has been closed");
                        
                        Flush ();