Ejemplo n.º 1
0
        protected override void WriteData()
        {
            try
            {
                int       blocksWrite = 0;
                BlockData block;
                byte[]    lenghtOfBlock;
                while (true && !IsError)
                {
                    using (var outputStream = new FileStream(OutputFile, FileMode.Append, FileAccess.Write))
                    {
                        if (BlockProcessed.TryTakeBlock(out block))
                        {
                            //получим размер сжатых данных для последующей декомпрессии
                            lenghtOfBlock = BitConverter.GetBytes(block.Bytes.Length);

                            /*запишем информацию о размере блока для последующей декомперссии и записи, вместо
                             * времени модификации файла в формате  MTIME  (согласно спецификации gzip) */
                            lenghtOfBlock.CopyTo(block.Bytes, 4);
                            outputStream.Write(block.Bytes, 0, block.Bytes.Length);
                            blocksWrite++;
                            ProgressInfo.Output(blocksWrite, BlocksCount);
                        }
                        else
                        {
                            if (blocksWrite == BlocksCount)
                            {
                                ProgressInfo.End();
                            }
                            else
                            {
                                throw new Exception("Can't write all blocks");
                            }
                            return;
                        }
                    }
                }
            }
            catch (IOException e)
            {
                ErrorOutput(e, "Unable to complete write operation due to insufficient RAM. Please close other applications and try again. ");
            }
            catch (OutOfMemoryException e)
            {
                ErrorOutput(e, "Not enough RAM to complete file write. Please close other applications and try again. ");
            }
            catch (Exception e)
            {
                ErrorOutput(e);
            }
            finally
            {
                EventWaitHandleWrite.Set();
            }
        }
Ejemplo n.º 2
0
 protected override void WriteData()
 {
     try
     {
         bool isSetLenght = false;
         int  blocksWrite = 0;
         while (true && !IsError)
         {
             BlockData block;
             if (BlockProcessed.TryTakeBlock(out block))
             {
                 using (var outputStream = new FileStream(OutputFile, FileMode.Open, FileAccess.Write))
                 {
                     if (!isSetLenght)
                     {
                         outputStream.SetLength(block.SizeFile);
                         isSetLenght = true;
                     }
                     outputStream.Seek(block.Position, SeekOrigin.Begin);
                     outputStream.Write(block.Bytes, 0, block.Bytes.Length);
                     blocksWrite++;
                     ProgressInfo.Output(blocksWrite, BlocksCount);
                 }
             }
             else
             {
                 if (blocksWrite >= BlocksCount)
                 {
                     ProgressInfo.End();
                 }
                 else
                 {
                     throw new Exception("Can't write all blocks");
                 }
                 return;
             }
         }
     }
     catch (IOException e)
     {
         ErrorOutput(e, "Unable to complete write operation due to insufficient RAM. Please close other applications and try again. ");
     }
     catch (OutOfMemoryException e)
     {
         ErrorOutput(e, "Not enough RAM to complete file write. Please close other applications and try again. ");
     }
     catch (Exception e)
     {
         ErrorOutput(e);
     }
     finally
     {
         EventWaitHandleWrite.Set();
     }
 }