예제 #1
0
        /// <summary>
        /// Decompresses one stream to another
        /// </summary>
        /// <exception cref="InvalidGZipException">Input stream not compatible with decompressor.</exception>
        /// <exception cref="ArgumentNullException">Input or output stream is nullable.</exception>
        /// <exception cref="ArgumentException">Input stream is not readable.</exception>
        /// <exception cref="ArgumentException">Output stream is not writable.</exception>
        public void Decompress(Stream input, Stream output)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }
            if (!input.CanRead)
            {
                throw new ArgumentException("Input stream is not readable", nameof(input));
            }
            if (!output.CanWrite)
            {
                throw new ArgumentException("Output stream is not writable", nameof(output));
            }

            using (var writer = new Consumer <byte[]>(
                       action: item => Write(item, output)))
            {
                var sorter = new SortedIterator <byte[]>(writer.Enqueue);
                using (var orderer = new Consumer <Chunk>(
                           action: item => sorter.Add(item.Index, item.Bytes)))
                    using (var decompressor = new Consumer <Chunk>(
                               action: item => DecompressAndPush(item, orderer),
                               degreeOfParallelism: _degreeOfParallelism))
                    {
                        ReadAndPush(input, decompressor);
                    }
            }
        }
        public void Run()
        {
            var numberOfLists    = 4;
            var numberOfElements = 8;
            var list             = GenerateSortedListOfList(numberOfLists, numberOfElements);
            var iterator         = new SortedIterator <int>(list);

            var count = 0;

            while (iterator.MoveNext())
            {
                Console.WriteLine(iterator.Current);
                count++;
            }

            if (count == numberOfLists * numberOfElements)
            {
                Console.WriteLine("All " + count + " Elements");
            }
            else
            {
                Console.WriteLine("Element count is wrong");
            }
        }