Пример #1
0
        /// <summary>
        /// Prepares object for sequential reading from the stream.
        /// The object is loaded with peice of text that contains the character pointer by <paramref name="initialPosition"/>.
        /// Data is loaded from the underlying stream.
        /// </summary>
        public void BeginReading(long initialPosition, TextAccessDirection direction)
        {
            if (readingStarted)
            {
                throw new InvalidOperationException("Cannot start reading session. Another reading session has already been started");
            }
            if (initialPosition < 0)
            {
                throw new ArgumentException("Negative positions are not allowed", "initialPosition");
            }

            readingStarted = true;

            this.direction     = direction;
            this.startPosition = new TextStreamPosition(initialPosition, textStreamPositioningParams);

            streamPositionToReadFromNextTime  = new TextStreamPosition(initialPosition, textStreamPositioningParams).StreamPositionAlignedToBlockSize;
            streamPositionAlignedToBufferSize = streamPositionToReadFromNextTime;
            decoderNeedsReloading             = EncodingNeedsReloading();

            textBufferLength   = 0;
            textBufferAsString = "";

            charsCutFromBeginningOfTextBuffer = 0;
            charsCutFromEndOfTextBuffer       = 0;

            AdvanceBufferInternal(0);
        }
Пример #2
0
 public ITextAccessIterator OpenIterator(long initialPosition, TextAccessDirection direction)
 {
     if (readingStarted)
     {
         throw new InvalidOperationException("Another iterator already exists. Dispose it first.");
     }
     BeginReading(initialPosition, direction);
     iterator.Open();
     return(iterator);
 }
Пример #3
0
        void TryBeginSplittingSession(FileRange.Range range, long startPosition, MessagesParserDirection direction)
        {
            bool posIsOutOfRange = DetectOutOfRangeCondition(range, startPosition, direction);

            if (!posIsOutOfRange)
            {
                TextAccessDirection accessDirection = direction == MessagesParserDirection.Forward ?
                                                      TextAccessDirection.Forward : TextAccessDirection.Backward;

                textIterator = textAccess.OpenIterator(startPosition, accessDirection);

                try
                {
                    headerPointer1     = textIterator.PositionToCharIndex(startPosition);
                    prevHeaderPointer1 = headerPointer1;
                }
                catch (ArgumentOutOfRangeException)
                {
                    posIsOutOfRange = true;
                }
            }

            headersCounter = 0;

            if (posIsOutOfRange)
            {
                this.range = new FileRange.Range();
                SetCachedCurrentBuffer("");
                currentMessageHeaderMatch = null;
                ReadingSessionCleanup();
            }
            else
            {
                this.range = range;
                SetCurrentDirection(direction);
                UpdateCachedCurrentBuffer();
                FindNextMessageStart();
            }
        }