public void Setup ()
		{
			var bytes = new byte[9 * 1024];
			int position = 0;

			random = new Random ();
			random.NextBytes (bytes);

			// this is our master stream, all operations on the chained stream
			// should match the results on this stream
			master = new MemoryStream (bytes);
			mbuf = new byte[4096];
			buf = new byte[4096];

			// write the content into the memory block stream in random chunks
			blocks = new MemoryBlockStream ();

			Assert.IsTrue (blocks.CanRead, "Expected to be able to read from the memory block stream.");
			Assert.IsTrue (blocks.CanWrite, "Expected to be able to write to the memory block stream.");
			Assert.IsTrue (blocks.CanSeek, "Expected to be able to seek in the memory block stream.");
			Assert.IsFalse (blocks.CanTimeout, "Did not expect to be able to set timeouts in the memory block stream.");

			while (position < bytes.Length) {
				int n = Math.Min (bytes.Length - position, random.Next () % 4096);
				blocks.Write (bytes, position, n);
				position += n;
			}

			blocks.Seek (0, SeekOrigin.Begin);
		}
Exemplo n.º 2
0
        public void Setup()
        {
            var bytes = new byte[9 * 1024];
            int position = 0;

            random = new Random ();
            random.NextBytes (bytes);

            // this is our master stream, all operations on the chained stream
            // should match the results on this stream
            master = new MemoryStream (bytes);
            mbuf = new byte[4096];
            buf = new byte[4096];

            // write the content into the memory block stream in random chunks
            blocks = new MemoryBlockStream ();
            while (position < bytes.Length) {
                int n = Math.Min (bytes.Length - position, random.Next () % 4096);
                blocks.Write (bytes, position, n);
                position += n;
            }

            blocks.Seek (0, SeekOrigin.Begin);
        }
Exemplo n.º 3
0
        unsafe BoundaryType ConstructMimePart(MimePart part, byte* inbuf)
        {
            BoundaryType found;
            Stream content;

            if (persistent) {
                long begin = GetOffset (inputIndex);
                long end;

                using (var measured = new MeasuringStream ()) {
                    found = ScanContent (inbuf, measured, true);
                    end = begin + measured.Length;
                }

                content = new BoundStream (stream, begin, end, true);
            } else {
                content = new MemoryBlockStream ();
                found = ScanContent (inbuf, content, true);
                content.Seek (0, SeekOrigin.Begin);
            }

            part.ContentObject = new ContentObject (content, part.ContentTransferEncoding);

            return found;
        }