diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-03-21 14:10:41 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-03-21 14:10:41 -0700 |
commit | ec8e3b27155297b790cadcfdebbe24fa2cbfa639 (patch) | |
tree | bd710d4964741fddad097b66e7b5e0b6eeca8b1b /samples/DotNetOpenAuth.ApplicationBlock/Util.cs | |
parent | 4197cf4144223397b3c1aa03eb136b34820c3684 (diff) | |
download | DotNetOpenAuth-ec8e3b27155297b790cadcfdebbe24fa2cbfa639.zip DotNetOpenAuth-ec8e3b27155297b790cadcfdebbe24fa2cbfa639.tar.gz DotNetOpenAuth-ec8e3b27155297b790cadcfdebbe24fa2cbfa639.tar.bz2 |
Added Blogger posting OAuth sample.
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock/Util.cs')
-rw-r--r-- | samples/DotNetOpenAuth.ApplicationBlock/Util.cs | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/Util.cs b/samples/DotNetOpenAuth.ApplicationBlock/Util.cs index 5001e2e..ea7da97 100644 --- a/samples/DotNetOpenAuth.ApplicationBlock/Util.cs +++ b/samples/DotNetOpenAuth.ApplicationBlock/Util.cs @@ -1,9 +1,10 @@ namespace DotNetOpenAuth.ApplicationBlock { using System; using System.Collections.Generic; + using System.IO; using DotNetOpenAuth.Messaging; - internal class Util { + internal static class Util { /// <summary> /// Enumerates through the individual set bits in a flag enum. /// </summary> @@ -25,5 +26,51 @@ Uri callback = MessagingUtilities.GetRequestUrlFromContext().StripQueryArgumentsWithPrefix("oauth_"); return callback; } + + /// <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> + /// <returns>The total number of bytes copied.</returns> + /// <remarks> + /// Copying begins at the streams' current positions. + /// The positions are NOT reset after copying is complete. + /// </remarks> + internal static int CopyTo(this Stream copyFrom, Stream copyTo) { + return CopyTo(copyFrom, copyTo, int.MaxValue); + } + + /// <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> + /// <param name="maximumBytesToCopy">The maximum bytes to copy.</param> + /// <returns>The total number of bytes copied.</returns> + /// <remarks> + /// Copying begins at the streams' current positions. + /// The positions are NOT reset after copying is complete. + /// </remarks> + internal static int CopyTo(this Stream copyFrom, Stream copyTo, int maximumBytesToCopy) { + if (copyFrom == null) { + throw new ArgumentNullException("copyFrom"); + } + if (copyTo == null) { + throw new ArgumentNullException("copyTo"); + } + + byte[] buffer = new byte[1024]; + int readBytes; + int totalCopiedBytes = 0; + while ((readBytes = copyFrom.Read(buffer, 0, Math.Min(1024, maximumBytesToCopy))) > 0) { + int writeBytes = Math.Min(maximumBytesToCopy, readBytes); + copyTo.Write(buffer, 0, writeBytes); + totalCopiedBytes += writeBytes; + maximumBytesToCopy -= writeBytes; + } + + return totalCopiedBytes; + } } } |