Appccelerate.IO.Streams.StreamExtensionMethods.CopyTo C# (CSharp) Method

CopyTo() public static method

Copies the input stream to the output stream.
or are null. /// is not readable or is /// not writable.
public static CopyTo ( this input, Stream output ) : void
input this The input stream.
output Stream The output stream.
return void
        public static void CopyTo(this Stream input, Stream output)
        {
            // assert these are the right kind of streams
            if (input == null)
            {
                throw new ArgumentNullException("input", "Input stream was null");
            }

            if (output == null)
            {
                throw new ArgumentNullException("output", "Output stream was null");
            }

            if (!input.CanRead)
            {
                throw new ArgumentException("Input stream must support CanRead");
            }

            if (!output.CanWrite)
            {
                throw new ArgumentException("Output stream must support CanWrite");
            }

            // skip if the input stream is empty (if seeking is supported)
            if (input.CanSeek)
            {
                if (input.Length == 0)
                {
                    return;
                }
            }

            // copy it
            const int Size = 4096;
            byte[] bytes = new byte[Size];
            int numBytes;
            while ((numBytes = input.Read(bytes, 0, Size)) > 0)
            {
                output.Write(bytes, 0, numBytes);
            }
        }
StreamExtensionMethods