using System;
using System.Data;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace net.ivoa.data {
    class TableImporter {
        public static CSVStreamInfo LearnFile(Stream s) {
            int rows = 0;
            using (StreamReader sr = new StreamReader(s)) {
                CSVStreamInfo ltokenizer = new CSVStreamInfo(sr.ReadLine());//parse colunm names
                while (!sr.EndOfStream) {
                    ++rows;
                    try {
                        ltokenizer.LearnColTypes(sr.ReadLine());
                    } catch (ColMismatchException cmm) {
                        throw new Exception("LINE " + (rows + 1) + ": " + cmm.Message);
                    } catch (UnknownTypeException ute) {
                        throw new Exception("LINE " + (rows + 1) + ": " + ute.Message);
                    }
                }
                return ltokenizer;
            }            
        }
        
    }
}
