Code Examples
A repository of 155 code examples for BeepBeep
ReadHttp.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2017 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 io;
19 
20 import ca.uqac.lif.cep.Connector;
21 import ca.uqac.lif.cep.ProcessorException;
22 import ca.uqac.lif.cep.io.HttpGet;
23 import ca.uqac.lif.cep.io.Print;
24 import ca.uqac.lif.cep.tmf.Pump;
25 
26 /**
27  * Read bytes from a remote source using HTTP.
28  *
29  * @author Sylvain HallĂ©
30  * @difficulty Easy
31  */
32 public class ReadHttp
33 {
34  public static void main(String[] args) throws ProcessorException, InterruptedException
35  {
36  /* We create an HttpGet processor stream reader, and instruct it to send
37  * requests to some URL (change it to a valid URL to make the program
38  * work). */
39  ///
40  HttpGet get = new HttpGet("http://example.com/some-url");
41 
42  /* We connect the reader to a pump, which will periodically ask
43  * the reader to read new characters from the input stream */
44  Pump pump = new Pump(10000);
45  Thread pump_thread = new Thread(pump);
46  Connector.connect(get, pump);
47 
48  /* We connect the output of the stream reader to a Print processor,
49  * that will merely re-print to the standard output what was received
50  * from the standard input. */
51  Print print = new Print();
52  Connector.connect(pump, print);
53 
54  /* We need to call start() on the pump's thread so that it can start
55  * listening to its input stream. */
56  pump_thread.start();
57 
58  /* Since our program does nothing else, it would stop right away.
59  * We put here an idle loop. You can stop it by pressing Ctrl+C. */
60  while (true)
61  {
62  Thread.sleep(10000);
63  }
64  ///
65  }
66 
67 }
Read bytes from a remote source using HTTP.
Definition: ReadHttp.java:32