Copies an Stream into another Stream.
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.IO;
namespace AntEater.Runtime.Tests.Services.Transformation
{
/// <summary>
/// Provides a set of Utilities.
/// </summary>
internal class Utilities
{
/// <summary>
/// Copies an Stream into another Stream.
/// </summary>
/// <param name="from">From.</param>
/// <param name="to">To.</param>
/// <param name="buffersize">The buffersize.</param>
/// <returns>The number of Bytes copied.</returns>
public static long CopyStream(Stream from, Stream to, int buffersize) {
byte[] buffer = new byte[buffersize];
long totalBytesCopied = 0;
int bytesRead = 0;
bytesRead = from.Read(buffer, 0, buffersize);
while(bytesRead > 0){
to.Write(buffer, 0, bytesRead);
totalBytesCopied += bytesRead;
bytesRead = from.Read(buffer, 0, buffersize);
}
return totalBytesCopied;
}
}
}
Related examples in the same category