Beispiel #1
0
        public int Read(byte[] array, int arrayOffset, int count)
        {
            PreConditions.Object(this).IsDisposedIf(_dataReaderPool == null);
            PreConditions.Argument("array").Value(array).IsNotNull();
            PreConditions.Argument("arrayOffset").Value(arrayOffset).InRange(0, array.Length);
            PreConditions.Argument("count").Value(count).InRange(0, (array.Length - arrayOffset));

            int totalBytesToRead = (int)Math.Min(count, (Length - Position));
            int bytesRead        = 0;

            while (bytesRead < totalBytesToRead)
            {
                IDataPacket fragment = _dataPacket.GetFragment(_position + bytesRead);

                int fragmentBytes     = (int)Math.Min((totalBytesToRead - bytesRead), fragment.Length);
                int fragmentBytesRead = _dataReaderPool.ReadInputFile(fragment.InputFile, fragment.StartOffset, array, (arrayOffset + bytesRead), fragmentBytes);
                bytesRead += fragmentBytesRead;

                // Completed or cancelled if not read the _entire_ fragment
                if (fragmentBytesRead != fragmentBytes)
                {
                    break;
                }
            }
            return(bytesRead);
        }
 public void DisposeFileDataReaders()
 {
     With.Mocks(_mockRepository).Expecting(delegate
     {
         _dataReader1.Expect(x => x.Dispose());
     }).Verify(delegate
     {
         _dataReaderPool.ReadInputFile(_inputFile1, 0L, new byte[16], 0, 8);
         _dataReaderPool.Dispose();
     });
 }