X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.IO%2FStreamWriter.cs;h=117ab7f5d60d3956726125d94fccec22526b9832;hb=0bbb93f17f89283094caf1725692b6f91f2f767c;hp=8781241630a6ae7080c077e462398583fee49adc;hpb=f9154436b59e0afc37c3f08710c56babcfe29ea2;p=mono.git diff --git a/mcs/class/corlib/System.IO/StreamWriter.cs b/mcs/class/corlib/System.IO/StreamWriter.cs index 8781241630a..117ab7f5d60 100644 --- a/mcs/class/corlib/System.IO/StreamWriter.cs +++ b/mcs/class/corlib/System.IO/StreamWriter.cs @@ -7,6 +7,29 @@ // // (C) Ximian, Inc. http://www.ximian.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.Text; using System; @@ -100,7 +123,7 @@ namespace System.IO { else mode = FileMode.Create; - internalStream = new FileStream (path, mode, FileAccess.Write); + internalStream = new FileStream (path, mode, FileAccess.Write, FileShare.Read); if (append) internalStream.Position = internalStream.Length; @@ -133,7 +156,7 @@ namespace System.IO { } } - protected override void Dispose (bool disposing) + protected override void Dispose (bool disposing) { if (!DisposedAlready && disposing && internalStream != null) { Flush(); @@ -147,7 +170,7 @@ namespace System.IO { decode_buf = null; } - public override void Flush () + public override void Flush () { if (DisposedAlready) throw new ObjectDisposedException("StreamWriter"); @@ -164,7 +187,7 @@ namespace System.IO { // Decode () is called when the buffer is full or we need to flash. // Decode () will use the encoding to get the bytes and but them inside // byte_buf. From byte_buf the data is finally outputted to the stream. - void FlushBytes () + void FlushBytes () { // write the encoding preamble only at the start of the stream if (!preamble_done && byte_pos > 0) { @@ -177,7 +200,7 @@ namespace System.IO { byte_pos = 0; } - void Decode () + void Decode () { if (byte_pos > 0) FlushBytes (); @@ -188,7 +211,7 @@ namespace System.IO { } } - public override void Write (char[] buffer, int index, int count) + public override void Write (char[] buffer, int index, int count) { if (DisposedAlready) throw new ObjectDisposedException("StreamWriter"); @@ -198,7 +221,7 @@ namespace System.IO { throw new ArgumentOutOfRangeException ("index", "< 0"); if (count < 0) throw new ArgumentOutOfRangeException ("count", "< 0"); - // re-ordered to avoid possible integer overflow + // re-ordered to avoid possible integer overflow if (index > buffer.Length - count) throw new ArgumentException ("index + count > buffer.Length"); @@ -207,7 +230,7 @@ namespace System.IO { Flush(); } - void LowLevelWrite (char[] buffer, int index, int count) + void LowLevelWrite (char[] buffer, int index, int count) { while (count > 0) { int todo = decode_buf.Length - decode_pos; @@ -227,7 +250,7 @@ namespace System.IO { public override void Write (char value) { if (DisposedAlready) - throw new ObjectDisposedException("StreamWriter"); + throw new ObjectDisposedException("StreamWriter"); // the size of decode_buf is always > 0 and // we check for overflow right away @@ -242,14 +265,14 @@ namespace System.IO { { if (DisposedAlready) throw new ObjectDisposedException("StreamWriter"); - + if (value != null) LowLevelWrite (value, 0, value.Length); if (iflush) Flush (); } - public override void Write (string value) + public override void Write (string value) { if (DisposedAlready) throw new ObjectDisposedException("StreamWriter"); @@ -262,10 +285,11 @@ namespace System.IO { public override void Close() { + closed = true; Dispose (true); } - ~StreamWriter () + ~StreamWriter () { Dispose(false); }