Bladeren bron

2009-11-07 Miguel de Icaza <[email protected]>

	* UnmanagedMemoryStream.cs: Move the CLS attribute to the methods
	that are unsafe.

	* Path.cs (Combine):e Fix implementation to follow docs (we need
	to reset the path if any of the combined paths is rooted), and add a
	couple of overloads;

	* FileStream.cs (Flush/flushToDisk): Implement.

	* Stream.cs (CopyTo): Implement.



svn path=/trunk/mcs/; revision=145640
Miguel de Icaza 16 jaren geleden
bovenliggende
commit
e9eafddcd6

+ 13 - 0
mcs/class/corlib/System.IO/ChangeLog

@@ -1,3 +1,16 @@
+2009-11-07  Miguel de Icaza  <[email protected]>
+
+	* UnmanagedMemoryStream.cs: Move the CLS attribute to the methods
+	that are unsafe.
+
+	* Path.cs (Combine):e Fix implementation to follow docs (we need
+	to reset the path if any of the combined paths is rooted), and add a
+	couple of overloads;
+
+	* FileStream.cs (Flush/flushToDisk): Implement.
+
+	* Stream.cs (CopyTo): Implement.
+
 2009-11-03  Miguel de Icaza  <[email protected]>
 
 	* FileStream.cs: Check the return value of MonoIO.Write and handle

+ 11 - 6
mcs/class/corlib/System.IO/FileStream.cs

@@ -831,14 +831,19 @@ namespace System.IO
 				throw new ObjectDisposedException ("Stream has been closed");
 
 			FlushBuffer ();
-			
-			// The flushing is not actually required, in
-			//the mono runtime we were mapping flush to
-			//`fsync' which is not the same.
-			//
-			//MonoIO.Flush (handle);
 		}
 
+#if NET_4_0
+		public virtual void Flush (bool flushToDisk)
+		{
+			FlushBuffer ();
+
+			// This does the fsync
+			if (flushToDisk)
+				MonoIO.Flush (handle);
+		}
+#endif
+
 		public virtual void Lock (long position, long length)
 		{
 			if (handle == MonoIO.InvalidHandle)

+ 12 - 1
mcs/class/corlib/System.IO/Path.cs

@@ -741,11 +741,12 @@ namespace System.IO {
 						l += DirectorySeparatorStr.Length;
 					}
 				}
-				l += s.Length;
 			}
 			var ret = new StringBuilder (l);
 			l = 0;
 			foreach (var s in paths){
+				if (IsPathRooted (s))
+					ret.Length = l = 0;
 				ret.Append (s);
 				if (l == 0 && need_sep)
 					ret.Append (DirectorySeparatorStr);
@@ -754,6 +755,16 @@ namespace System.IO {
 
 			return ret.ToString ();
 		}
+
+		public static string Combine (string path1, string path2, string path3)
+		{
+			return Combine (new string [] { path1, path2, path3 });
+		}
+
+		public static string Combine (string path1, string path2, string path3, string path4)
+		{
+			return Combine (new string [] { path1, path2, path3, path4 });
+		}
 #endif
 	}
 }

+ 24 - 0
mcs/class/corlib/System.IO/Stream.cs

@@ -260,6 +260,30 @@ namespace System.IO
 			if (result.Exception != null)
 				throw result.Exception;
 		}
+
+#if NET_4_0
+		public void CopyTo (Stream destination)
+		{
+			CopyTo (destination, 16*1024);
+		}
+
+		public void CopyTo (Stream destination, int bufferSize)
+		{
+			if (destination == null)
+				throw new ArgumentNullException ("destination");
+			if (!CanRead)
+				throw new NotSupportedException ("This stream does not support reading");
+			if (!destination.CanWrite)
+				throw new NotSupportedException ("This destination stream does not support writing");
+			if (bufferSize <= 0)
+				throw new ArgumentOutOfRangeException ("bufferSize");
+
+			var buffer = new byte [bufferSize];
+			int nread;
+			while ((nread = Read (buffer, 0, bufferSize)) != 0)
+				destination.Write (buffer, 0, nread);
+		}
+#endif
 	}
 
 	class NullStream : Stream

+ 4 - 2
mcs/class/corlib/System.IO/UnmanagedMemoryStream.cs

@@ -36,7 +36,6 @@ using System.Runtime.InteropServices;
 
 namespace System.IO
 {
-	[CLSCompliantAttribute(false)]
 	public class UnmanagedMemoryStream : Stream
 	{
 		long length;
@@ -54,16 +53,19 @@ namespace System.IO
 		{
 			closed = true;
 		}
-		
+
+		[CLSCompliantAttribute(false)]
 		public unsafe UnmanagedMemoryStream (byte *pointer, long length)
 		{
 			Initialize (pointer, length, length, FileAccess.Read);
 		}
 		
+		[CLSCompliantAttribute(false)]
 		public unsafe UnmanagedMemoryStream (byte *pointer, long length, long capacity, FileAccess access)
 		{
 			Initialize (pointer, length, capacity, access);
 		}
+		
 #endregion
 	
 #region Properties