Exemplo n.º 1
0
 private bool CanReadString()
 {
     if (_ftPage.IsLastPage)
         return false;
     byte[] buffer = _ftPage.GetNextPageBuffer();
     if (_reader != null)
     {
         _reader.Dispose();
     }
     _reader = new FTStreamReader(buffer);
     return true;
 }
Exemplo n.º 2
0
        private bool CanReadData(int length)
        {
            if(_reader == null || _reader.Position + length > _reader.Length)
            {
                if (_ftPage.IsLastPage)
                {
                    return false;
                }
                else
                {
                    int reading = 0;
                    if(_reader == null)
                        reading = length;
                    else
                    {
                        reading = length - (int)(_reader.Length - _reader.Position);
                    }
                    List<byte[]> bufferList = new List<byte[]>(2);
                    int readedCount = 0;
                    do
                    {
                        LogWriter.Instance.WriteLine("---------------------------------------------------------------------------------------------------");
                        LogWriter.Instance.WriteLine("current page is end. will read next page");
                        LogWriter.Instance.WriteLine("---------------------------------------------------------------------------------------------------");

                        byte[] bufferTemp = _ftPage.GetNextPageBuffer();
                        bufferList.Add(bufferTemp);
                        reading -= bufferTemp.Length;
                        readedCount += bufferTemp.Length;

                        LogWriter.Instance.WriteLine("---------------------------------------------------------------------------------------------------");
                        LogWriter.Instance.Write("next page bytes index is :");
                        LogWriter.Instance.Write(_ftPage.CurrentPageIndex.ToString());
                        LogWriter.Instance.Write(". Length is :");
                        LogWriter.Instance.WriteLine(bufferTemp.Length.ToString());
                        LogWriter.Instance.WriteLine("---------------------------------------------------------------------------------------------------");
                    } while (reading > 0);

                    byte[] buffer = new byte[readedCount];
                    reading = 0;
                    foreach (byte[] eachBuffer in bufferList)
                    {
                        Array.Copy(eachBuffer, 0, buffer, reading, eachBuffer.Length);
                        reading += eachBuffer.Length;
                    }

                    if (_reader == null)
                    {
                        _reader = new FTStreamReader(buffer);
                    }
                    else if (_reader.Position == _reader.Length)
                    {
                        _reader.Dispose();
                        _reader = new FTStreamReader(buffer);
                    }
                    else
                    {
                        byte[] lastBuffer = _reader.ReadBytes((int)(_reader.Length - _reader.Position));
                        byte[] allBuffer = new byte[lastBuffer.Length + buffer.Length];
                        Array.Copy(lastBuffer, 0, allBuffer, 0, lastBuffer.Length);
                        Array.Copy(buffer, 0, allBuffer, lastBuffer.Length, buffer.Length);
                        _reader.Dispose();
                        _reader = new FTStreamReader(allBuffer);
                    }

                }
            }
            return true;
        }