From 099f56bc862224f42e838ffc5871f27b4007d3da Mon Sep 17 00:00:00 2001 From: Duncan Mak Date: Wed, 9 Jun 2004 17:10:54 +0000 Subject: [PATCH] * 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. svn path=/trunk/mcs/; revision=29123 --- mcs/class/corlib/System.IO/BufferedStream.cs | 12 +++++++++++- mcs/class/corlib/System.IO/ChangeLog | 8 ++++++++ mcs/class/corlib/System.IO/FileStream.cs | 15 ++++++--------- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/mcs/class/corlib/System.IO/BufferedStream.cs b/mcs/class/corlib/System.IO/BufferedStream.cs index d70ad125374..c256188821c 100644 --- a/mcs/class/corlib/System.IO/BufferedStream.cs +++ b/mcs/class/corlib/System.IO/BufferedStream.cs @@ -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")); } - } + } } } diff --git a/mcs/class/corlib/System.IO/ChangeLog b/mcs/class/corlib/System.IO/ChangeLog index 85639c95b18..0ce85c2cbb3 100644 --- a/mcs/class/corlib/System.IO/ChangeLog +++ b/mcs/class/corlib/System.IO/ChangeLog @@ -1,3 +1,11 @@ +2004-06-09 Duncan Mak + + * 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 * FileStream.cs: re-enabled ignoring broken pipe errors when reading. diff --git a/mcs/class/corlib/System.IO/FileStream.cs b/mcs/class/corlib/System.IO/FileStream.cs index 2466fbf359a..556a6344066 100644 --- a/mcs/class/corlib/System.IO/FileStream.cs +++ b/mcs/class/corlib/System.IO/FileStream.cs @@ -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 (); -- 2.25.1