A compression stream for reading or writing from/to BizTalk message part fragment format.
Inheritance: Stream
Beispiel #1
0
        /// <summary>
        /// Deserializes the message part data within the given source stream and writes the
        /// content into the given destination stream.
        /// </summary>
        public static int DeserializeMessageTo(Stream source, Stream destination)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            using (var decoder = new BizTalkMessagePartStream(source, StreamMode.Read))
            {
                byte[] buffer = new byte[8192];

                int total = 0;
                int read;

                do
                {
                    read = decoder.Read(buffer, 0, buffer.Length);
                    destination.Write(buffer, 0, read);
                    total += read;
                }while (read > 0);

                return(total);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Writes the decoded contents of all fragments to the given stream, optionally caching
        /// loaded fragments for future access. Not caching improves memory usage and may improve
        /// performance. Don't cache if you're never going to access the fragments after. Caching
        /// has no effect if fragments already have been loaded for this message part.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="cacheFragments">
        /// if set to <c>true</c> cache fragments for future access
        /// via the Fragments property.
        /// </param>
        public int WriteTo(Stream s, bool cacheFragments)
        {
            int total = 0;

            IEnumerable <BizTalkFragment> fragments;

            if (!cacheFragments || this._fragments != null)
            {
                fragments = this.Fragments;
            }
            else
            {
                fragments = LoadFragments();
            }

            byte[] buf = new byte[8192];
            int    c;

            foreach (var fragment in fragments)
            {
                using (var ds = new MemoryStream(fragment.ImagePart))
                    using (var bz = new BizTalkMessagePartStream(ds, StreamMode.Read))
                    {
                        while ((c = bz.Read(buf, 0, buf.Length)) > 0)
                        {
                            s.Write(buf, 0, c);
                            total += c;
                        }
                    }
            }

            return(total);
        }
        /// <summary>
        /// Writes the decoded contents of all fragments to the given stream, optionally caching
        /// loaded fragments for future access. Not caching improves memory usage and may improve
        /// performance. Don't cache if you're never going to access the fragments after. Caching
        /// has no effect if fragments already have been loaded for this message part.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="cacheFragments">
        /// if set to <c>true</c> cache fragments for future access 
        /// via the Fragments property.
        /// </param>
        public int WriteTo(Stream s, bool cacheFragments)
        {
            int total = 0;

            IEnumerable<BizTalkFragment> fragments;

            if (!cacheFragments || this._fragments != null)
                fragments = this.Fragments;
            else
                fragments = LoadFragments();

            byte[] buf = new byte[8192];
            int c;

            foreach (var fragment in fragments)
            {
                using (var ds = new MemoryStream(fragment.ImagePart))
                using (var bz = new BizTalkMessagePartStream(ds, StreamMode.Read))
                {
                    while ((c = bz.Read(buf, 0, buf.Length)) > 0)
                    {
                        s.Write(buf, 0, c);
                        total += c;
                    }
                }
            }

            return total;
        }