Read() public method

Reads a block of bytes from the current stream and writes the data to buffer.
is null. /// or is less than 0 -or- /// and will exceed length. /// The stream is closed.
public Read ( byte buffer, int startIndex, int length ) : int
buffer byte When this method returns, contains the specified byte array with the values between and ( + - 1) replaced by the characters read from the current stream.
startIndex int The byte offset in at which to begin reading.
length int The maximum number of bytes to read.
return int
        public void Test4()
        {
            MemoryStream ms = new MemoryStream();
            BlockAllocatedMemoryStream ms2 = new BlockAllocatedMemoryStream();

            for (int x = 0; x < 10000; x++)
            {
                int value = Random.Int32;
                ms.Write(value);
                ms.Write((byte)value);
                ms2.Write(value);
                ms2.Write((byte)value);
            }

            for (int x = 0; x < 10000; x++)
            {
                long position = Random.Int64Between(0, ms.Length - 5);
                ms.Position = position;
                ms2.Position = position;

                if (ms.ReadInt32() != ms2.ReadInt32())
                    throw new Exception();
                if (ms.ReadNextByte() != ms2.ReadNextByte())
                    throw new Exception();
            }

            for (int x = 0; x < 10000; x++)
            {
                byte[] buffer1 = new byte[100];
                byte[] buffer2 = new byte[100];

                long position = Random.Int64Between(0, (long)(ms.Length * 1.1));
                int readLength = Random.Int32Between(0, 100);
                ms.Position = position;
                ms2.Position = position;

                if (ms.Read(buffer1, 99 - readLength, readLength) != ms2.Read(buffer2, 99 - readLength, readLength))
                {
                    CompareBytes(buffer1, buffer2);
                }

            }

            Compare(ms, ms2);
        }