Exemplo n.º 1
0
        public void TestStreamWriteAndReadAndFlush()
        {
            ObjectPool <byte[]> pool = new ObjectPool <byte[]>(() => { return(new byte[10]); });

            using (ChunkedBuffer stream = new ChunkedBuffer(pool))
            {
                Assert.AreEqual(0, stream.ReadPosition);
                Assert.AreEqual(0, stream.WritePosition);

                stream.Write(TestData, 0, TestData.Length);

                Assert.AreEqual(TestData.Length, stream.WritePosition);
                Assert.AreEqual(0, stream.ReadPosition);

                Assert.AreEqual(0, pool.ObjectsInPool);
                Assert.AreEqual(Math.Round((float)TestData.Length / 10f, MidpointRounding.AwayFromZero), pool.TotalNumberOfObjects);

                StreamReader reader = new StreamReader(stream.Stream);

                Assert.AreEqual(Encoding.UTF8.GetString(TestData, 0, TestData.Length), reader.ReadToEnd());

                Assert.AreEqual(TestData.Length, stream.ReadPosition);
                Assert.AreEqual(TestData.Length, stream.WritePosition);

                stream.Flush();

                Assert.AreEqual(0, stream.ReadPosition);
                Assert.AreEqual(0, stream.WritePosition);
            }
        }
Exemplo n.º 2
0
        public void TestStreamWriteAndReadAndFlush()
        {
            ObjectPool<byte[]> pool = new ObjectPool<byte[]>(() => { return new byte[10]; });

            using (ChunkedBuffer stream = new ChunkedBuffer(pool))
            {
                Assert.AreEqual(0, stream.ReadPosition);
                Assert.AreEqual(0, stream.WritePosition);

                stream.Write(TestData, 0, TestData.Length);

                Assert.AreEqual(TestData.Length, stream.WritePosition);
                Assert.AreEqual(0, stream.ReadPosition);

                Assert.AreEqual(0, pool.ObjectsInPool);
                Assert.AreEqual(Math.Round((float)TestData.Length / 10f, MidpointRounding.AwayFromZero), pool.TotalNumberOfObjects);

                StreamReader reader = new StreamReader(stream.Stream);

                Assert.AreEqual(Encoding.UTF8.GetString(TestData, 0, TestData.Length), reader.ReadToEnd());

                Assert.AreEqual(TestData.Length, stream.ReadPosition);
                Assert.AreEqual(TestData.Length, stream.WritePosition);

                stream.Flush();

                Assert.AreEqual(0, stream.ReadPosition);
                Assert.AreEqual(0, stream.WritePosition);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Flushes this stream and clears any read pooled memory chunks.
 /// </summary>
 public override void Flush()
 {
     chunkedBuffer.Flush();
 }