/** * 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); } }
/** * Creates a new {@code ObservableSensor} using the specified * {@link SensorParams} * * @param params */ internal ObservableSensor(SensorParams @params) { if ([email protected]("ONSUB")) { throw new ArgumentException("Passed improperly formed Tuple: no key for \"ONSUB\""); } this.@params = @params; IObservable <string> obs = null; object publisher = @params.Get("ONSUB"); if (publisher is Publisher) { obs = ((Publisher)publisher).Observable(); } else if (publisher is PublisherSupplier) { obs = ((PublisherSupplier)publisher).Get().Observable(); } else { obs = (IObservable <string>)@params.Get("ONSUB"); } //IEnumerator<string> observerator = obs.GetEnumerator(); //IEnumerator<string> iterator = new CustomIterator<string>( // () => // { // bool moved = observerator.MoveNext(); // return new System.Tuple<bool, string>(moved, observerator.Current); // }); //Iterator<String> iterator = new Iterator<String>() { // public boolean hasNext() { return observerator.hasNext(); } // public String next() // { // return observerator.next(); // } //}; //int characteristics = Spliterator.SORTED | Spliterator.ORDERED; //Spliterator<string> spliterator = Spliterators.spliteratorUnknownSize(iterator, characteristics); this.stream = BatchedCsvStream <string> .Batch( new Stream <string>(obs), BATCH_SIZE, DEFAULT_PARALLEL_MODE, HEADER_SIZE); }
public void TestInputIntegerArray() { Publisher manual = Publisher.GetBuilder() .AddHeader("sdr_in") .AddHeader("sarr") .AddHeader("B") .Build(); Sensor <ObservableSensor <string[]> > sensor = Sensor <ObservableSensor <string[]> > .Create( ObservableSensor <string[]> .Create, SensorParams.Create(SensorParams.Keys.Obs, new Object[] { "name", manual })); int i = 0; var t = new Task(() => { BatchedCsvStream <string[]> iStream = (BatchedCsvStream <string[]>)sensor.GetInputStream(); Stream <string[]> oStream = (Stream <string[]>)iStream._contentStream; Assert.AreEqual(2, ((string[])oStream.First()).Length); }); //(t = new Thread() { // int i = 0; // public void run() // { // assertEquals(2, ((String[])sensor.getInputStream().findFirst().get()).length); // } //}).start(); int[][] ia = getArrayFromFile(ResourceLocator.Path(typeof(Resources), "1_100.csv")); manual.OnNext(Arrays.ToString(ia[0]).Trim()); t.Start(); try { t.Wait(); } catch (Exception e) { Console.WriteLine(e); Assert.Fail(); } }
/** * 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); } } }