Beispiel #1
0
        private void writeBlocksThread()
        {
            if (_lockedThreadsException != null)
            {
                return;
            }

            while (true)
            {
                var block = new BlockWithPosition();

                while (_decompressedBlocks.TryPop(out block) == false && _lockedIsFileDecompressed == false)
                {
                }
                if (block == null)
                {
                    break;
                }
                lock (_writeLocker)
                {
                    try
                    {
                        _blockWriter.WriteBlock(_outputFile, block.Position, block.Block);
                    }
                    catch (Exception ex)
                    {
                        _lockedThreadsException = ex;
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        public void TryPop_should_return_last_Pushed_block()
        {
            var blockStack = new ConcurrentBlockStack();
            var expected   = new BlockWithPosition(new byte[] { 1, 2, 3 }, 22);

            blockStack.Push(new BlockWithPosition(new byte[] { 2, 3, 4 }, 11));
            blockStack.Push(expected);

            var tempExpected = new BlockWithPosition();

            blockStack.TryPop(out tempExpected);

            Assert.AreEqual(expected, tempExpected);
        }
Beispiel #3
0
        private void decompressBlockThread()
        {
            if (_lockedThreadsException != null)
            {
                return;
            }

            while (true)
            {
                if (_decompressedBlocks.Count() >= _threadsCount)
                {
                    continue;
                }

                BlockWithPosition block = null;
                while (_readedBlocks.TryPop(out block) == false && _lockedIsFileClosed == false)
                {
                }
                try
                {
                    if (block == null)
                    {
                        break;
                    }
                    block.Block = _blockDecompressor.DecompressBlock(block.Block);
                }
                catch (Exception ex)
                {
                    _lockedThreadsException = ex;
                    break;
                }

                _decompressedBlocks.Push(block);
            }
            lock (_currentDecompressedIndexLocker)
            {
                _currentDecompressedIndex++;
                if (_currentDecompressedIndex == _threadsCount)
                {
                    _lockedIsFileDecompressed = true;
                }
            }
        }
Beispiel #4
0
        private void writeBlockThread()
        {
            if (_lockedThreadsException != null)
            {
                return;
            }

            while (true)
            {
                BlockWithPosition block = null;

                while (_compressedBlocks.TryPop(out block) == false && _lockedIsFileCompressed == false)
                {
                }
                if (block == null)
                {
                    break;
                }

                var blockWithPosLen = new byte[8 + 4 + block.Block.Length];
                BitConverter.GetBytes(block.Position).CopyTo(blockWithPosLen, 0);
                BitConverter.GetBytes(block.Block.Length).CopyTo(blockWithPosLen, 8);

                block.Block.CopyTo(blockWithPosLen, 12);
                lock (_writeLocker)
                {
                    try
                    {
                        _blockWriter.WriteBlock(_outputFile, _outputFile.Position, blockWithPosLen);
                    }
                    catch (Exception ex)
                    {
                        _lockedThreadsException = ex;
                        break;
                    }
                }
            }
        }