blob: f0f38fe095e0a980c9f3cdd191dda652befaf481 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package main;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import mining.OAuthStream;
import mining.Stream;
import mining.StreamListener;
import mining.TwitterApi;
import org.json.JSONObject;
/**
* A command that reads a stream from a stream listener and writes the data to a
* file.
*
* @author Maurice Laveaux
*/
public class StreamCommand implements StreamListener {
/**
* A private reference for the stream.
*/
private final Stream m_stream;
public StreamCommand(final TwitterApi api) {
m_stream = new OAuthStream();
}
@Override
public void notify(JSONObject data) {
try {
// TODO: add the results to the main database.
// For now write to a file
File file = new File("database.txt");
FileWriter writer = new FileWriter(file, true);
writer.write("\n\r" + data.toString());
writer.flush();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
|