public override void ReadFile(string source, ref TaskPool readPool, int bufferSize) { try { using var br = new BinaryReader(new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.None)); _originLength = br.ReadInt64(); _blockCount = br.ReadInt64(); for (int count = 0; count < _blockCount; count++) { int blockNumber = br.ReadInt32(); int blockLength = br.ReadInt32(); byte[] blockValue = br.ReadBytes(blockLength); if (blockValue == null) { throw new ArgumentNullException("blockValue", "Incorrect block value"); } if (!readPool.TrySet(blockNumber, blockValue)) { return; } } } catch (Exception e) { _delete = true; Terminate(); Console.WriteLine(e.Message); return; } }
public override void ReadFile(string sourceFile, ref TaskPool readPool, int bufferSize) { try { FileInfo file = new FileInfo(sourceFile); _sourceFileSize = file.Length; _blockCount = file.Length / bufferSize; if (file.Length % bufferSize > 0) { _blockCount++; } } catch (Exception e) { _delete = true; Terminate(); logger.Warn(e.Message); return; } try { using var binReader = new BinaryReader(new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.None)); for (int blockNumber = 0; blockNumber < _blockCount; blockNumber++) { byte[] blockValue = binReader.ReadBytes(bufferSize); if (blockValue == null) { throw new ArgumentNullException("blockValue", "Incorrect block value"); } if (!readPool.TrySet(blockNumber, blockValue)) { return; } } } catch (Exception e) { _delete = true; Terminate(); logger.Warn(e.Message); return; } }
public override void Handle(ref TaskPool readPool, ref TaskPool writePool) { int blockNumber = -1; byte[] blockValue = null; while (true) { try { if (!readPool.TryGet(out blockNumber, out blockValue)) { return; } if (blockValue == null) { break; } byte[] decompressedBlock = ApplyGZip(blockValue); if (!writePool.TrySet(blockNumber, decompressedBlock)) { return; } } catch (Exception e) { _delete = true; Terminate(); Console.WriteLine(e.Message); return; } } }