Code Examples
A repository of 155 code examples for BeepBeep
CsvReaderExample.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2018 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package tuples;
19 
20 import java.io.InputStream;
21 
22 import ca.uqac.lif.cep.Connector;
23 import ca.uqac.lif.cep.Pullable;
24 import ca.uqac.lif.cep.io.ReadLines;
25 import ca.uqac.lif.cep.tuples.Tuple;
26 import ca.uqac.lif.cep.tuples.TupleFeeder;
27 
28 /**
29  * Read tuples from a CSV file using the
30  * {@link ca.uqac.lif.cep.tuples.TupleFeeder TupleFeeder} processor.
31  * Graphically, this chain of processor can be described as follows:
32  * <p>
33  * <img src="./doc-files/tuples/CsvReaderExample.png" alt="Processor graph">
34  * <p>
35  * The output of this program is:
36  * <pre>
37  * ((A,3),(B,2),(C,1))
38  * ((A,1),(B,7),(C,1))
39  * ((A,4),(B,1),(C,2))
40  * ((A,1),(B,8),(C,3))
41  * ((A,6),(B,3),(C,5))
42  * </pre>
43  * @author Sylvain HallĂ©
44  * @difficulty Easy
45  */
46 public class CsvReaderExample
47 {
48  public static void main(String[] args)
49  {
50  ///
51  InputStream is = CsvReaderExample.class.getResourceAsStream("file1.csv");
52  ReadLines reader = new ReadLines(is);
53  TupleFeeder tuples = new TupleFeeder();
54  Connector.connect(reader, tuples);
55  Pullable p = tuples.getPullableOutput();
56  Tuple tup = null;
57  while (p.hasNext())
58  {
59  tup = (Tuple) p.next();
60  System.out.println(tup);
61  }
62  ///
63  //* Let us now examine how to interact with a Tuple object
64  Object o = tup.get("A");
65  System.out.println(o + "," + o.getClass().getSimpleName());
66  //*
67  }
68 }
Manipulate tuples.
Read tuples from a CSV file using the TupleFeeder processor.