view Implab/Formats/ReaderScanner.cs @ 187:dd4a3590f9c6 ref20160224

Reworked cancelation handling, if the cancel handler isn't specified the OperationCanceledException will be handled by the error handler Any unhandled OperationCanceledException will cause the promise cancelation
author cin
date Tue, 19 Apr 2016 17:35:20 +0300
parents 4f82e0f161c3
children
line wrap: on
line source

using System;
using System.IO;

namespace Implab.Formats {
    public class ReaderScanner: TextScanner {
        const int CHUNK_SIZE = 1024*4;
        const int BUFFER_MAX = CHUNK_SIZE*1024;

        readonly TextReader m_reader;

        public ReaderScanner(TextReader reader, int limit, int chunk) : base(limit, chunk) {
            Safe.ArgumentNotNull(reader, "reader");
            m_reader = reader;
        }

        public ReaderScanner(TextReader reader) : this(reader, BUFFER_MAX, CHUNK_SIZE) {
        }

        protected override int Read(char[] buffer, int offset, int size) {
            return m_reader.Read(buffer, offset, size);
        }

        protected override void Dispose(bool disposing) {
            if (disposing)
                Safe.Dispose(m_reader);
            base.Dispose(disposing);
        }
    }
}