Example #1
0
 protected override void CompressOrDecompressLogic(object i, DataBlockModel buffer)
 {
     using (var memoryStream = new MemoryStream(buffer.CompressedDataBuffer))
     {
         using (var gZipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
         {
             gZipStream.Read(buffer.DataBuffer, 0, buffer.DataBuffer.Length);
             var block = new DataBlockModel(buffer.IdBlock, buffer.DataBuffer.ToArray());
             QueueFromWriter.AddDataToWriting(block);
         }
     }
 }
Example #2
0
        public void AddDataToWriting(DataBlockModel dataBlock)
        {
            lock (locker)
            {
                while (dataBlock.IdBlock != idBlock)
                {
                    Monitor.Wait(locker);
                }

                queue.Enqueue(dataBlock);
                idBlock++;
                Monitor.PulseAll(locker);
            }
        }
Example #3
0
        protected override void CompressOrDecompressLogic(object i, DataBlockModel buffer)
        {
            using (var memoryStream = new MemoryStream())
            {
                using (var gZipStream = new GZipStream(memoryStream, CompressionMode.Compress, true))
                {
                    gZipStream.Write(buffer.DataBuffer, 0, buffer.DataBuffer.Length);
                }
                byte[] compressedData = memoryStream.ToArray();
                var    compressBuffer = new DataBlockModel(buffer.IdBlock, compressedData);
                QueueFromWriter.AddDataToWriting(compressBuffer);
            }
            var doneManualResetEvents = manualResetEvents[(int)i];

            doneManualResetEvents.Set();
        }
Example #4
0
        protected override void ReadCompressOrDecompress(FileStream fileInput, ProgressBar pb)
        {
            int inkrement = 0;

            while (fileInput.Position < fileInput.Length && !Cancel)
            {
                byte[] lengthBuffer = new byte[8];
                fileInput.Read(lengthBuffer, 0, lengthBuffer.Length);
                int    blockLength    = BitConverter.ToInt32(lengthBuffer, 4);
                byte[] compressedData = new byte[blockLength];
                fileInput.Read(compressedData, 8, blockLength - 8);
                lengthBuffer.CopyTo(compressedData, 0);

                var compressBuffer = new DataBlockModel(inkrement, new byte[ByteSize], compressedData);
                QueueFromReader.AddDataToWriting(compressBuffer);
                inkrement++;
                pb.drawTextProgressBar((int)fileInput.Position);
            }
        }
Example #5
0
        public void addDataToBuffer(byte[] buffer)
        {
            if (buffer == null)
            {
                throw new InvalidOperationException("buffer is null");
            }
            lock (locker)
            {
                if (isDead)
                {
                    throw new InvalidOperationException("Queue already stopped");
                }

                DataBlockModel newBlock = new DataBlockModel(idBlock, buffer);
                queue.Enqueue(newBlock);
                idBlock++;
                Monitor.PulseAll(locker);
            }
        }
Example #6
0
 protected override void GetBytes(DataBlockModel buffer)
 {
     BitConverter.GetBytes(buffer.DataBuffer.Length).CopyTo(buffer.DataBuffer, 4);
 }
Example #7
0
 protected virtual void GetBytes(DataBlockModel buffer)
 {
 }
Example #8
0
 protected abstract void CompressOrDecompressLogic(object i, DataBlockModel buffer);