Example #1
0
        public static void Forward(Stream source, int sourceOffset, Stream target, int length)
        {
            PagedMemoryStream pagedMemoryStream = source as PagedMemoryStream;

            if (pagedMemoryStream != null)
            {
                pagedMemoryStream.WriteTo(sourceOffset, target, length);
            }
            else
            {
                MemoryStream memoryStream = source as MemoryStream;
                if (memoryStream != null)
                {
                    target.Write(memoryStream.GetBuffer(), sourceOffset, length);
                }
                else
                {
                    long position = source.Position;
                    source.Position = (long)sourceOffset;
                    byte[] buffer = new byte[65536];
                    int    num    = length / 65536;
                    for (int index = 0; index < num; ++index)
                    {
                        source.Read(buffer, 0, 65536);
                        target.Write(buffer, 0, 65536);
                    }
                    int count = length - num * 65536;
                    if (count > 0)
                    {
                        source.Read(buffer, 0, count);
                        target.Write(buffer, 0, count);
                    }
                    source.Position = position;
                }
            }
        }
Example #2
0
        public static void Forward(Stream source, Stream target)
        {
            PagedMemoryStream pagedMemoryStream = source as PagedMemoryStream;

            if (pagedMemoryStream != null)
            {
                pagedMemoryStream.WriteTo(target);
            }
            else
            {
                MemoryStream memoryStream = source as MemoryStream;
                if (memoryStream != null)
                {
                    target.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
                }
                else
                {
                    long position = source.Position;
                    source.Position = 0L;
                    byte[] buffer = new byte[65536];
                    int    num    = (int)(source.Length / 65536L);
                    for (int index = 0; index < num; ++index)
                    {
                        source.Read(buffer, 0, 65536);
                        target.Write(buffer, 0, 65536);
                    }
                    int count = (int)(source.Length - (long)(num * 65536));
                    if (count > 0)
                    {
                        source.Read(buffer, 0, count);
                        target.Write(buffer, 0, count);
                    }
                    source.Position = position;
                }
            }
        }