* StringReader.cs: Added some ObjectDisposedExceptions.
* StringWriter.cs: Added some ObjectDisposedExceptions.
* BinaryReader.cs: Added some ObjectDisposedExceptions.
svn path=/trunk/mcs/; revision=13576
int m_encoding_max_byte;
byte[] m_buffer;
+
+ private bool m_disposed = false;
public BinaryReader(Stream input) : this(input, Encoding.UTF8Unmarked) {
}
public virtual void Close() {
Dispose (true);
+ m_disposed = true;
}
protected virtual void Dispose (bool disposing)
if (disposing && m_stream != null)
m_stream.Close ();
+ m_disposed = true;
m_buffer = null;
m_encoding = null;
m_stream = null;
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");
}
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");
}
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");
}
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");
}
+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
private int nextChar;
private int sourceLength;
+ private bool disposed = false;
public StringReader( string s ) {
public override void Close() {
Dispose( true );
+ disposed = true;
}
protected override void Dispose (bool disposing)
}
public override int Peek() {
+
+ if (disposed)
+ throw new ObjectDisposedException ("StringReader", "Cannot read from a closed StringReader");
+
if( nextChar >= sourceLength ) {
return -1;
} else {
}
public override int Read() {
+
+ if (disposed)
+ throw new ObjectDisposedException ("StringReader", "Cannot read from a closed StringReader");
+
if( nextChar >= sourceLength ) {
return -1;
} else {
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 ) {
// 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;
}
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;
public class StringWriter : TextWriter {\r
\r
private StringBuilder internalString;\r
+ private bool disposed = false;\r
\r
public StringWriter() {\r
internalString = new StringBuilder();\r
\r
public override void Close() {\r
Dispose( true );\r
+ disposed = true;\r
}\r
\r
protected override void Dispose (bool disposing)\r
// 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
}\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