public IDataPacket GetSubPacket(long offset, long length)
        {
            PreConditions.Argument("offset").Value(offset).InRange(0L, (Length - 1L));
            PreConditions.Argument("length").Value(length).InRange(1L, (Length - offset));

            if ((offset == 0) && (length == Length))
            {
                return(this);                   // Sub-packet is the entire packet
            }

            long firstLength = _firstDataPacket.Length;

            if (offset >= firstLength)
            {
                return(_secondDataPacket.GetSubPacket((offset - firstLength), length));
            }

            long relativeEndOffset = (offset + length);

            if (relativeEndOffset <= firstLength)
            {
                return(_firstDataPacket.GetSubPacket(offset, length));
            }

            IDataPacket firstSubPacket  = _firstDataPacket.GetSubPacket(offset, (firstLength - offset));
            IDataPacket secondSubPacket = _secondDataPacket.GetSubPacket(0, (relativeEndOffset - firstLength));

            return(firstSubPacket.Append(secondSubPacket));
        }
 public IDataPacket GetSubPacket(long offset, long length)
 {
     if (Detector != null)
     {
         throw new ArgumentException("Can not append to a codec stream");
     }
     return(_dataPacket.GetSubPacket(offset, length));
 }
Ejemplo n.º 3
0
        public void GetSubPacket()
        {
            IDataPacket subPacket = _dataPacket.GetSubPacket(SubPacketOffset, SubPacketLength);

            Assert.IsInstanceOfType(typeof(DataPacket), subPacket, "Type");
            Assert.AreSame(_inputFile1, subPacket.InputFile, "InputFile");
            Assert.AreEqual(SubPacketLength, subPacket.Length, "Length");
            Assert.AreEqual(SubPacketStartOffset, subPacket.StartOffset, "StartOffset");
            Assert.AreEqual(SubPacketEndOffset, subPacket.EndOffset, "EndOffset");
        }
 public IDataPacket GetSubPacket(long offset, long length)
 {
     return(_dataPacket.GetSubPacket(offset, length));
 }
 public void GetSubPacketFirstSubPacket()
 {
     _dataPacket1.Stub(x => x.GetSubPacket(SubPacketOffset, SubPacketLength)).Return(_subPacket1);
     Assert.AreSame(_subPacket1, _dataPacket.GetSubPacket(SubPacketOffset, SubPacketLength));
 }
        private IResultNode RescanDetectable(IFragment detectable, IProgressReporter progressReporter, IDataReaderPool dataReaderPool)
        {
            IDataPacket data = detectable;

            if (detectable is ICodecStream)
            {
                // Data is specified relative to the codec stream (see IDetectable.Data)
                data = GetData(detectable as ICodecStream, progressReporter, dataReaderPool);

                if (progressReporter.CancellationPending)
                {
                    return(null);                                                      // The rescan is cancelled
                }
                var codecStream = detectable as ICodecStream;
                if (codecStream.ReferenceHeader != null)
                {
                    long off = codecStream.ReferenceHeaderOffset;
                    if (off == 0L)
                    {
                        data = codecStream.ReferenceHeader.Append(data);
                    }
                    else
                    {
                        data = data.GetSubPacket(0, off).Append(codecStream.ReferenceHeader).Append(data.GetSubPacket(off, data.Length - off));
                    }
                }
            }
            if (detectable is IDataBlock)
            {
                IDataBlock dataBlock = detectable as IDataBlock;
                if (dataBlock.ReferenceHeader != null)
                {
                    long off = dataBlock.ReferenceHeaderOffset;
                    if (off == 0L)
                    {
                        data = dataBlock.ReferenceHeader.Append(detectable);
                    }
                    else
                    {
                        data = detectable.GetSubPacket(0, off).Append(dataBlock.ReferenceHeader).Append(detectable.GetSubPacket(off, detectable.Length - off));
                    }
                }
            }

            IResultNode results;

            using (IDataReader dataReader = new ProgressDataReader(new FragmentedDataReader(data, dataReaderPool), progressReporter))
            {
                IScanContext scanContext = _createScanContext(detectable.InputFile.Project);
                scanContext.Detectors = detectable.Detectors;

                IDataBlockBuilder dataBlockBuilder = _createDataBlockBuilder();
                dataBlockBuilder.Detectors = scanContext.Detectors;
                dataBlockBuilder.InputFile = detectable.InputFile;

                IDetector  detector = GetDetector(detectable);
                IDataBlock newDataBlock;

                var codecDetector = (detector as ICodecDetector);
                if (codecDetector == null)
                {
                    newDataBlock = detector.DetectData(dataReader, dataBlockBuilder, scanContext);
                }
                else
                {
                    var referenceHeaders = codecDetector.ReferenceHeaders;
                    try
                    {
                        // Disable reference headers during rescan
                        codecDetector.ReferenceHeaders = null;
                        newDataBlock = detector.DetectData(dataReader, dataBlockBuilder, scanContext);
                    }
                    finally
                    {
                        // Restore reference headers
                        codecDetector.ReferenceHeaders = referenceHeaders;
                    }
                }

                if (!progressReporter.CancellationPending && newDataBlock == null)
                {
                    RetrievedDetectableIsDifferentThanTheOneRetrievedDuringTheInitialScan();
                    return(null);
                }

                results = scanContext.Results;

                // Check cancellation request and results / data block
                if (!progressReporter.CancellationPending && (detectable is IDataBlock) && !IsDataBlockCorrect(detectable as IDataBlock, newDataBlock))
                {
                    //RetrievedDetectableIsDifferentThanTheOneRetrievedDuringTheInitialScan();
                    //return null;
                }
            }
            return(results);
        }