2003-04-13 Ville Palo <vi64pa@kolumbus.fi>
authorVille Palo <ville@mono-cvs.ximian.com>
Sun, 13 Apr 2003 13:13:20 +0000 (13:13 -0000)
committerVille Palo <ville@mono-cvs.ximian.com>
Sun, 13 Apr 2003 13:13:20 +0000 (13:13 -0000)
* StringReader.cs: Added some ObjectDisposedExceptions.
* StringWriter.cs: Added some ObjectDisposedExceptions.
* BinaryReader.cs: Added some ObjectDisposedExceptions.

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

mcs/class/corlib/System.IO/BinaryReader.cs
mcs/class/corlib/System.IO/ChangeLog
mcs/class/corlib/System.IO/StringReader.cs
mcs/class/corlib/System.IO/StringWriter.cs

index 747f67817ac609d3be4c965b00f77ff57995ccee..e1cfa08f11fbecaf8952fd34ce69fd85b237a09a 100644 (file)
@@ -17,6 +17,8 @@ namespace System.IO {
                int m_encoding_max_byte;
 
                byte[] m_buffer;
+               
+               private bool m_disposed = false;
 
                public BinaryReader(Stream input) : this(input, Encoding.UTF8Unmarked) {
                }
@@ -41,6 +43,7 @@ namespace System.IO {
 
                public virtual void Close() {
                        Dispose (true);
+                       m_disposed = true;
                }
                
                protected virtual void Dispose (bool disposing)
@@ -48,6 +51,7 @@ namespace System.IO {
                        if (disposing && m_stream != null)
                                m_stream.Close ();
 
+                       m_disposed = true;
                        m_buffer = null;
                        m_encoding = null;
                        m_stream = null;
@@ -79,6 +83,10 @@ namespace System.IO {
 
                public virtual int PeekChar() {
                        if(m_stream==null) {
+                               
+                               if (m_disposed)
+                                       throw new ObjectDisposedException ("BinaryReader", "Cannot read from a closed BinaryReader.");
+
                                throw new IOException("Stream is invalid");
                        }
 
@@ -107,6 +115,10 @@ namespace System.IO {
 
                public virtual int Read(byte[] buffer, int index, int count) {
                        if(m_stream==null) {
+
+                               if (m_disposed)
+                                       throw new ObjectDisposedException ("BinaryReader", "Cannot read from a closed BinaryReader.");
+
                                throw new IOException("Stream is invalid");
                        }
                        
@@ -130,6 +142,10 @@ namespace System.IO {
 
                public virtual int Read(char[] buffer, int index, int count) {
                        if(m_stream==null) {
+
+                               if (m_disposed)
+                                       throw new ObjectDisposedException ("BinaryReader", "Cannot read from a closed BinaryReader.");
+
                                throw new IOException("Stream is invalid");
                        }
                        
@@ -201,6 +217,10 @@ namespace System.IO {
 
                public virtual byte[] ReadBytes(int count) {
                        if(m_stream==null) {
+
+                               if (m_disposed)
+                                       throw new ObjectDisposedException ("BinaryReader", "Cannot read from a closed BinaryReader.");
+
                                throw new IOException("Stream is invalid");
                        }
                        
index 8a87e7895f8f1671cbc5780ed0385ece6655087f..403e9e5888b47940188921e3c8745df88330c93b 100644 (file)
@@ -1,3 +1,9 @@
+2003-04-13  Ville Palo <vi64pa@kolumbus.fi>
+
+       * StringReader.cs: Added some ObjectDisposedExceptions.
+       * StringWriter.cs: Added some ObjectDisposedExceptions.
+       * BinaryReader.cs: Added some ObjectDisposedExceptions.
+       
 2003-04-13  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * FileStream.cs: fixed the windows build. This is an mcs bug. I'll
index 7a1872ffaea3d62f7c9f15b18dcd0d20375e017a..2ea9392f07a168c19e525184252a0877d9fa5398 100644 (file)
@@ -16,6 +16,7 @@ namespace System.IO {
 
                private int nextChar;
                private int sourceLength;
+               private bool disposed = false;
 
                public StringReader( string s ) {
 
@@ -30,6 +31,7 @@ namespace System.IO {
 
                public override void Close() {
                        Dispose( true );
+                       disposed = true;
                }
 
                protected override void Dispose (bool disposing)
@@ -39,6 +41,10 @@ namespace System.IO {
                }
 
                public override int Peek() {
+
+                       if (disposed) 
+                               throw new ObjectDisposedException ("StringReader", "Cannot read from a closed StringReader");
+
                        if( nextChar >= sourceLength ) {
                                return -1;
                        } else {
@@ -47,6 +53,10 @@ namespace System.IO {
                }
 
                public override int Read() {
+
+                       if (disposed) 
+                               throw new ObjectDisposedException ("StringReader", "Cannot read from a closed StringReader");
+
                        if( nextChar >= sourceLength ) {
                                return -1;
                        } else {
@@ -62,6 +72,9 @@ namespace System.IO {
 
                public override int Read( char[] buffer, int index, int count ) {
 
+                       if (disposed) 
+                               throw new ObjectDisposedException ("StringReader", "Cannot read from a closed StringReader");
+
                        if( buffer == null ) {
                                throw new ArgumentNullException();
                        } else if( buffer.Length - index < count ) {
@@ -98,6 +111,9 @@ namespace System.IO {
                         // HOWEVER, the MS implementation returns the rest of the string if no \r and/or \n is found
                         // in the string
 
+                       if (disposed) 
+                               throw new ObjectDisposedException ("StringReader", "Cannot read from a closed StringReader");
+
                        if (nextChar >= source.Length)
                                return null;
 
@@ -128,6 +144,10 @@ namespace System.IO {
                }
 
                 public override string ReadToEnd() {
+
+                       if (disposed) 
+                               throw new ObjectDisposedException ("StringReader", "Cannot read from a closed StringReader");
+
                         string toEnd = source.Substring( nextChar, sourceLength - nextChar );
                         nextChar = sourceLength;
                         return toEnd;
index f85efd40baa63e48e3d39ed971eebc5f5ec3e3ad..06d55013407768af77dfe0a63e33a15bb9c5146e 100644 (file)
@@ -11,6 +11,7 @@ namespace System.IO {
         public class StringWriter : TextWriter {\r
                 \r
                 private StringBuilder internalString;\r
+               private bool disposed = false;\r
 \r
                 public StringWriter() {\r
                         internalString = new StringBuilder();\r
@@ -41,6 +42,7 @@ namespace System.IO {
 \r
                 public override void Close() {\r
                         Dispose( true );\r
+                       disposed = true;\r
                 }\r
 \r
                 protected override void Dispose (bool disposing)\r
@@ -48,6 +50,7 @@ namespace System.IO {
                        // MS.NET doesn't clear internal buffer.\r
                        // internalString = null;\r
                        base.Dispose (disposing);\r
+                       disposed = true;\r
                }\r
 \r
                 public virtual StringBuilder GetStringBuilder() {\r
@@ -59,14 +62,26 @@ namespace System.IO {
                 }\r
 \r
                 public override void Write( char value ) {\r
+\r
+                       if (disposed) \r
+                               throw new ObjectDisposedException ("StringWriter", "Cannot write to a closed StringWriter");\r
+\r
                         internalString.Append( value );\r
                 }\r
 \r
                 public override void Write( string value ) {\r
+\r
+                       if (disposed) \r
+                               throw new ObjectDisposedException ("StringWriter", "Cannot write to a closed StringWriter");\r
+\r
                         internalString.Append( value );\r
                 }\r
 \r
                 public override void Write( char[] buffer, int index, int count ) {\r
+\r
+                       if (disposed) \r
+                               throw new ObjectDisposedException ("StringReader", "Cannot write to a closed StringWriter");\r
+\r
                         if( buffer == null ) {\r
                                 throw new ArgumentNullException();\r
                         } else if( index < 0 || count < 0 ) {\r