diff options
Diffstat (limited to 'src/DotNetOAuth/Messaging/MessagingUtilities.cs')
-rw-r--r-- | src/DotNetOAuth/Messaging/MessagingUtilities.cs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/DotNetOAuth/Messaging/MessagingUtilities.cs b/src/DotNetOAuth/Messaging/MessagingUtilities.cs index 7c95696..88aea0c 100644 --- a/src/DotNetOAuth/Messaging/MessagingUtilities.cs +++ b/src/DotNetOAuth/Messaging/MessagingUtilities.cs @@ -8,6 +8,7 @@ namespace DotNetOAuth.Messaging { using System;
using System.Collections.Generic;
using System.Collections.Specialized;
+ using System.IO;
using System.Linq;
using System.Net;
using System.Text;
@@ -46,6 +47,36 @@ namespace DotNetOAuth.Messaging { }
/// <summary>
+ /// Copies the contents of one stream to another.
+ /// </summary>
+ /// <param name="copyFrom">The stream to copy from, at the position where copying should begin.</param>
+ /// <param name="copyTo">The stream to copy to, at the position where bytes should be written.</param>
+ /// <remarks>
+ /// Copying begins at the streams' current positions.
+ /// The positions are NOT reset after copying is complete.
+ /// </remarks>
+ internal static void CopyTo(this Stream copyFrom, Stream copyTo) {
+ if (copyFrom == null) {
+ throw new ArgumentNullException("copyFrom");
+ }
+ if (copyTo == null) {
+ throw new ArgumentNullException("copyTo");
+ }
+ if (!copyFrom.CanRead) {
+ throw new ArgumentException(MessagingStrings.StreamUnreadable, "copyFrom");
+ }
+ if (!copyTo.CanWrite) {
+ throw new ArgumentException(MessagingStrings.StreamUnwritable, "copyTo");
+ }
+
+ byte[] buffer = new byte[1024];
+ int readBytes;
+ while ((readBytes = copyFrom.Read(buffer, 0, 1024)) > 0) {
+ copyTo.Write(buffer, 0, readBytes);
+ }
+ }
+
+ /// <summary>
/// Concatenates a list of name-value pairs as key=value&key=value,
/// taking care to properly encode each key and value for URL
/// transmission. No ? is prefixed to the string.
|