Ejemplo n.º 1
0
        public string ReadLine(Encoding encoding)
        {
            // this reader will not close underlying stream, but will do buffered read
            int save_pos = _position;             // save current position
            StreamReaderNoClose reader = new StreamReaderNoClose(this, encoding, false);
            StringBuilder       sb     = reader.ReadLineWithTerminator();

            reader.Close();

            // calc the actual bytes read, and set the position by force
            var actualByteCount = sb == null ? 0 : encoding.GetByteCount(sb.ToString());

            _position = Math.Min(save_pos + actualByteCount, (int)Length);

            // then remove the terminating \r, \n, \r\n
            if (sb == null)
            {
                return(null);
            }
            else
            {
                while (sb.Length > 0 && (sb[sb.Length - 1] == '\r' || sb[sb.Length - 1] == '\n'))
                {
                    sb.Length--;
                }
                return(sb.ToString());
            }
        }
Ejemplo n.º 2
0
        public string ReadLine(Encoding encoding)
        {
            // this reader will not close underlying stream, but will do buffered read
            int save_pos = _position; // save current position
            StreamReaderNoClose reader = new StreamReaderNoClose(this, encoding, false);
            StringBuilder sb = reader.ReadLineWithTerminator();
            reader.Close();

            // calc the actual bytes read, and set the position by force
            var actualByteCount = sb == null ? 0 : encoding.GetByteCount(sb.ToString());
            _position = Math.Min(save_pos + actualByteCount, (int)Length);

            // then remove the terminating \r, \n, \r\n
            if (sb == null)
                return null;
            else
            {
                while (sb.Length > 0 && (sb[sb.Length - 1] == '\r' || sb[sb.Length - 1] == '\n')) sb.Length--;
                return sb.ToString();
            }
        }