示例#1
0
        /// <summary>
        ///     Coies the current stream onto the given one
        /// </summary>
        /// <param name="stream"></param>
        public void MoveTo(FifoStream stream)
        {
            stream._lastBuffer = _lastBuffer;
            _lastBuffer        = null;
            var count = _localBuffer.Count;

            for (var i = 0; i < count; i++)
            {
                stream._localBuffer.Enqueue(_localBuffer.Dequeue());
            }

            stream._length += _length;
            _length         = 0;
            _localBuffer.Clear();
        }
示例#2
0
        /// <summary>
        ///     Moves the required amount of bytes onto a new fifostream
        ///     Warning: Unused buffer segments can appear
        /// </summary>
        /// <param name="requiredBytes"></param>
        /// <returns></returns>
        public FifoStream FastMove(int requiredBytes)
        {
            _lastBuffer = null;

            var dStream = new FifoStream(_ringBufferProvider);

            while (requiredBytes > 0 && _length > 0 && _localBuffer.Count > 0)
            {
                var cBuf    = _localBuffer.Peek();
                var cBufLen = cBuf.Length;

                if (cBufLen <= requiredBytes)
                {
                    dStream._localBuffer.Enqueue(cBuf);
                    dStream._length += cBufLen;
                    requiredBytes   -= cBufLen;
                    _length         -= cBufLen;
                    _localBuffer.Dequeue();
                }
                else
                {
                    var nBuf      = _ringBufferProvider.Create();
                    var readBytes =
                        nBuf.Write(cBuf.Value, cBuf.Low, requiredBytes);

                    cBuf.Low      += readBytes;
                    _length       -= readBytes;
                    requiredBytes -= readBytes;

                    dStream._length += readBytes;
                    dStream._localBuffer.Enqueue(nBuf);

                    if (cBuf.Length == 0)
                    {
                        _localBuffer.Dequeue().ReIntegrate();
                    }
                }
            }

            return(dStream);
        }