Exemplo n.º 1
0
        public static string SafeReadToEnd(this StreamReader source)
        {
            if (source.BaseStream == null)
            {
                throw new InvalidOperationException("ReaderClosed");
            }
            source.CheckAsyncTaskInProgress();
            var charBuffer = source.charBuffer();
            var charLen = source.charLen(); var charPos = source.charPos();
            var b = new StringBuilder(charLen - charPos);

            try
            {
                while (true)
                {
                    b.Append(charBuffer, charPos, charLen - charPos);
                    source.charPos(charLen);
                    source.ReadBuffer();
                    charLen = source.charLen(); charPos = source.charPos();
                    if (charLen <= 0)
                    {
                        return(b.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                if (e.InnerException != null && !(e.InnerException is IOException))
                {
                    throw e.InnerException;
                }
                charLen = source.charLen(); charPos = source.charPos();
                if (charLen > 0)
                {
                    b.Append(charBuffer, charPos, charLen - charPos);
                }
                return(b.ToString());
            }
        }