diff options
Diffstat (limited to 'src/main/StreamCommand.java')
-rw-r--r-- | src/main/StreamCommand.java | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/main/StreamCommand.java b/src/main/StreamCommand.java index 058cbd6..f0f38fe 100644 --- a/src/main/StreamCommand.java +++ b/src/main/StreamCommand.java @@ -1,10 +1,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 + * @author Maurice Laveaux */ -public class StreamCommand { - +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); + } + } } |