Esempio n. 1
0
        public LinesReader(Stream stream, char[] buffer = null)
        {
            try
            {
                if (buffer is null)
                {
                    m_buffer = ArrayPool <char> .Shared.Rent(1024 * 32);

                    m_bufferCreated = true;
                }
                else
                {
                    m_buffer = buffer;
                }

                m_rdr = new StreamReader(stream);
            }
            catch
            {
                if (m_rdr != null)
                {
                    DisposeUtils.Dispose(ref m_rdr);
                }
                if (m_bufferCreated == true && m_buffer != null)
                {
                    ArrayPool <char> .Shared.Return(m_buffer);
                }
                m_bufferCreated = false;
                m_buffer        = null;
                throw;
            }
        }
Esempio n. 2
0
        public LinesReader(string filename, char[] buffer = null)
        {
            try
            {
                if (buffer is null)
                {
                    m_buffer = ArrayPool <char> .Shared.Rent(1024 * 32);

                    m_bufferCreated = true;
                }
                else
                {
                    m_buffer = buffer;
                }

                var fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
                m_rdr = new StreamReader(fs);
            }
            catch
            {
                if (m_rdr != null)
                {
                    DisposeUtils.Dispose(ref m_rdr);
                }
                if (m_bufferCreated == true && m_buffer != null)
                {
                    ArrayPool <char> .Shared.Return(m_buffer);
                }
                m_buffer = null;
                throw;
            }
        }
Esempio n. 3
0
        public void Dispose()
        {
            if (m_rdr != null)
            {
                DisposeUtils.Dispose(ref m_rdr);
            }

            if (m_bufferCreated == true)
            {
                var buf = m_buffer;
                m_buffer = null;
                if (buf != null)
                {
                    ArrayPool <char> .Shared.Return(buf);
                }
            }
        }