Beispiel #1
0
        protected override void Write(CustomConcurentQueue outputBlocks, string outputFilePath, object i)
        {
            int lastBlockIndex = 0;

            doneEvents[(int)i] = new ManualResetEvent(false);

            using (var writer = new BinaryWriter(File.Open(outputFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)))
            {
                while (outputBlocks.Count > 0 || !_isProcessed)
                {
                    if (outputBlocks.Count == 0)
                    {
                        continue;
                    }

                    writer.BaseStream.Seek(0, SeekOrigin.End);
                    var block = outputBlocks.GetByIndex(lastBlockIndex);

                    if (block.Equals(default(KeyValuePair <int, byte[]>)))
                    {
                        continue;
                    }

                    writer.Write(block.Value);
                    Interlocked.Increment(ref lastBlockIndex);
                }
            }

            doneEvents[(int)i].Set();
        }
Beispiel #2
0
        protected override void Write(CustomConcurentQueue outputBlocks, string outputFilePath, object i)
        {
            int lastBlockIndex = 0;

            doneEvents[(int)i] = new ManualResetEvent(false);

            using (FileStream _fileCompressed = new FileStream(outputFilePath + ".gz", FileMode.Append))
            {
                while (!_isProcessed || outputBlocks.Count > 0)
                {
                    if (outputBlocks.Count == 0)
                    {
                        continue;
                    }

                    var block = outputBlocks.GetByIndex(lastBlockIndex);

                    if (block.Equals(default(KeyValuePair <int, byte[]>)))
                    {
                        continue;
                    }

                    BitConverter.GetBytes(block.Value.Length).CopyTo(block.Value, 4);
                    _fileCompressed.Write(block.Value, 0, block.Value.Length);
                    Interlocked.Increment(ref lastBlockIndex);
                }
            }

            doneEvents[(int)i].Set();
        }