Read MemoryStream To End - CSharp System.IO

CSharp examples for System.IO:MemoryStream

Description

Read MemoryStream To End

Demo Code


using System.Text;
using System.Security.Principal;
using System.IO;/* www.ja  v a  2s  . c o  m*/
using System;

public class Main{
        public static byte[] ReadToEnd(this MemoryStream stream)
        {
            long remainingBytes = stream.Length - stream.Position;
            if(remainingBytes > int.MaxValue)
            {
                throw new ArgumentOutOfRangeException("stream");
            }
            byte[] buffer = new byte[remainingBytes];
            stream.Read(buffer, 0, (int)remainingBytes);
            return buffer;
        }
}

Related Tutorials