Write() публичный Метод

When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
public Write ( byte buffer, int offset, int count ) : void
buffer byte /// An array of bytes. This method copies bytes from /// /// to the current stream. ///
offset int /// The zero-based byte offset in at which to begin copying bytes to the /// current stream. ///
count int The number of bytes to be written to the current stream.
Результат void
Пример #1
0
        public void PoolMemoryStreamReadWriteBytes()
        {
            //assume
            const int count = 20000;
            var bytes = new byte[count];
            for(int i = 0; i < count; i++)
            {
                bytes[i] = (byte)((i - byte.MinValue)%byte.MaxValue);
            }

            //act
            var stream = new PoolMemoryStream();
            stream.Write(bytes, 0, count);
            stream.Position = 0;

            var readBytes = new byte[count];
            int actual = 0;
            int read = 0;
            do
            {
                read = stream.Read(readBytes, read, count - read);
                actual += read;
            } while(read > 0);

            //assert
            Assert.AreEqual(stream.Length, actual, "not all written bytes can be read");
            Assert.IsTrue(readBytes.SequenceEqual(bytes), "returned bytes differ from written bytes");


            stream.Dispose();
        }
Пример #2
0
        public void PoolMemoryStreamWriteBytes()
        {
            //assume
            const int count = 20000;
            var bytes = new byte[count];
            for(int i = 0; i < count; i++)
            {
                bytes[i] = (byte)((i - byte.MinValue)%byte.MaxValue);
            }

            //act
            var stream = new PoolMemoryStream();
            stream.Write(bytes, 0, count);

            //assert
            Assert.AreEqual(stream.Length, count, "Unexpected stream length");
            Assert.AreEqual(stream.Position, count, "Unexpected position");
            Assert.IsTrue(stream.Capacity >= count, "Unexpected capacity");
        }
Пример #3
0
        public void PoolMemoryStreamWriteCopyToAsync()
        {
            //assume
            const int count = 20000;
            var bytes = new byte[count];
            for(int i = 0; i < count; i++)
            {
                bytes[i] = (byte)((i - byte.MinValue)%byte.MaxValue);
            }

            //act
            var stream = new PoolMemoryStream();
            stream.Write(bytes, 0, count);
            stream.Position = 0;

            var target = new MemoryStream();
            stream.CopyToAsync(target).Wait();

            var readBytes = target.ToArray();

            //assert
            Assert.AreEqual(stream.Length, readBytes.Length, "not all written bytes are copied");
            Assert.IsTrue(readBytes.SequenceEqual(bytes), "returned bytes differ from written bytes");
        }