コード例 #1
0
ファイル: CustomFileSensor.cs プロジェクト: ArtiDi/HTM.Net
        /**
         * Protected constructor. Instances of this class should be obtained
         * through the {@link #create(SensorParams)} factory method.
         *
         * @param params
         */
        protected CustomFileSensor(SensorParams @params)
            : base(@params)
        {
            string pathStr = (string)@params.Get("PATH");

            FileInfo f = new FileInfo(pathStr);

            if (!f.Exists)
            {
                throw new ArgumentException("Passed improperly formed Tuple: invalid PATH: " + @params.Get("PATH"));
            }

            try
            {
                IStream <string> fileStream = new Stream <string>(YieldingFileReader.ReadAllLines(f.FullName, Encoding.UTF8));
                this.stream = BatchedCsvStream <string> .Batch(fileStream, BATCH_SIZE, DEFAULT_PARALLEL_MODE, HEADER_SIZE,
                                                               s =>
                {
                    return(s.Split('\t'));
                });
            }
            catch (IOException e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #2
0
        /**
         * Protected constructor. Instances of this class should be obtained
         * through the {@link #create(SensorParams)} factory method.
         *
         * @param params
         */
        protected FileSensor(SensorParams @params)
        {
            this.@params = @params;

            if ([email protected]("PATH"))
            {
                throw new ArgumentException("Passed improperly formed Tuple: no key for \"PATH\"");
            }

            string pathStr = (string)@params.Get("PATH");

            if (pathStr.IndexOf("!") != -1)
            {
                pathStr = pathStr.Substring("file:".Length);

                IStream <string> stream = GetZipEntryStream(pathStr);
                this.stream = BatchedCsvStream <string> .Batch(stream, BATCH_SIZE, DEFAULT_PARALLEL_MODE, HEADER_SIZE);
            }
            else
            {
                FileInfo f = new FileInfo(pathStr);
                if (!f.Exists)
                {
                    throw new ArgumentException("Passed improperly formed Tuple: invalid PATH: " + @params.Get("PATH"));
                }

                try
                {
                    IStream <string> fileStream = new Stream <string>(YieldingFileReader.ReadAllLines(f.FullName, Encoding.UTF8));
                    this.stream = BatchedCsvStream <string> .Batch(fileStream, BATCH_SIZE, DEFAULT_PARALLEL_MODE, HEADER_SIZE);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e);
                }
            }
        }