public void CreateDataReader() { With.Mocks(_mockRepository).Expecting(delegate { _createDataReader.Expect(x => x(_dataPacket, _dataReaderPool)).Return(_dataReaderOld1); }).Verify(delegate { Assert.AreSame(_dataReaderOld1, _dataReaderPool.CreateDataReader(_dataPacket)); }); }
/// <summary> /// Saves the <paramref name="dataPacket"/> sequentially to a single file with /// given <paramref name="filePath"/>. /// </summary> /// <param name="dataPacket">The data packet to save</param> /// <param name="detectors">The detectors used to create data packet</param> /// <param name="dataReaderPool">The shared pool of file data readers</param> /// <param name="filePath">The path name of the file to write to</param> /// <param name="progressReporter">For reporting progress and checking cancellation</param> /// <param name="createForensicIntegrityLog">Create a forensic integrity log file along with the normal output</param> /// <exception cref="ArgumentNullException">If any argument is <c>null</c></exception> /// <exception cref="IOException">On error writing the output file</exception> public void Save(IDataPacket dataPacket, IEnumerable <IDetector> detectors, IDataReaderPool dataReaderPool, string filePath, IProgressReporter progressReporter, bool createForensicIntegrityLog) { PreConditions.Argument("dataPacket").Value(dataPacket).IsNotNull(); PreConditions.Argument("detectors").Value(detectors).IsNotNull().And.DoesNotContainNull(); PreConditions.Argument("dataReaderPool").Value(dataReaderPool).IsNotNull(); PreConditions.Argument("filePath").Value(filePath).IsNotNull().And.IsNotEmpty(); PreConditions.Argument("progressReporter").Value(progressReporter).IsNotNull(); if (progressReporter.CancellationPending) { return; } using (IDataWriter dataWriter = _createDataWriter(filePath)) { using (IDataReader dataReader = dataReaderPool.CreateDataReader(dataPacket, progressReporter)) { dataWriter.Write(dataReader); } } if (createForensicIntegrityLog) { string logFileName = string.Format("{0}.csv", filePath); using (FileStream fs = new FileStream(logFileName, FileMode.Create, FileAccess.Write, FileShare.Read)) { _forensicIntegrityLog.Log(dataPacket, detectors, filePath, fs, ForensicLogType.CopiedData); } } }
public void Scan(IInputFile inputFile, IProgressReporter progressReporter) { PreConditions.Argument("inputFile").Value(inputFile).IsNotNull(); PreConditions.Argument("progressReporter").Value(progressReporter).IsNotNull(); if (inputFile.Length == 0L) { return; } _inputFile = inputFile; using (IDataReader dataReader = _dataReaderPool.CreateDataReader(inputFile.CreateDataPacket())) { Scan(dataReader, progressReporter); } }
private byte[] ReadDataPacket(IDataPacket dataPacket) { var data = new byte[dataPacket.Length]; using (IDataReaderPool pool = _poolCreator()) using (IDataReader reader = pool.CreateDataReader(dataPacket)) { reader.Read(data, 0, data.Length); } return(data); }
/// <summary> /// Writes <paramref name="dataPacket"/> to <paramref name="fileName"/>. /// </summary> /// <param name="dataPacket">the data packet to write</param> /// <param name="fileName">the name of the file to write to</param> public static void WriteDataPacket(IDataPacket dataPacket, IDataReaderPool dataReaderPool, string fileName) { byte[] buffer = new byte[512 * 1024]; using (FileStream outputFileStream = new FileStream(fileName, FileMode.Create)) using (IDataReader dataReader = dataReaderPool.CreateDataReader(dataPacket)) { int count; while ((count = dataReader.Read(buffer, 0, buffer.Length)) > 0) { outputFileStream.Write(buffer, 0, count); dataReader.Position += count; } } }
/// <summary> /// Saves the <paramref name="inputFile"/> to the file with given /// <paramref name="filePath"/>. /// </summary> /// <param name="inputFile">The <see cref="IInputFile"/> to save</param> /// <param name="detectors">The detectors (empty/ignored)</param> /// <param name="dataReaderPool">Ignored</param> /// <param name="filePath">The path name of the file to write to</param> /// <param name="progressReporter">For reporting progress and checking cancellation</param> /// <exception cref="ArgumentNullException">If any argument is <c>null</c></exception> /// <exception cref="IOException">On error writing the output file</exception> public void Save(IInputFile inputFile, IEnumerable <IDetector> detectors, IDataReaderPool dataReaderPool, string filePath, IProgressReporter progressReporter, bool createForensicIntegrityLog) { PreConditions.Argument("inputFile").Value(inputFile).IsNotNull(); PreConditions.Argument("detectors").Value(detectors).IsNotNull(); PreConditions.Argument("filePath").Value(filePath).IsNotNull().And.IsNotEmpty(); PreConditions.Argument("progressReporter").Value(progressReporter).IsNotNull(); if (progressReporter.CancellationPending) { return; } using (IDataWriter dataWriter = _createDataWriter(filePath)) using (IDataReader dataReader = dataReaderPool.CreateDataReader(inputFile.CreateDataPacket(), progressReporter)) { dataWriter.Write(dataReader); } }