summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-01 16:03:40 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-01 16:03:40 +0200
commit9c2f6a8112f6ad40789046dddd5c5ae6a79e213d (patch)
treededbfd331f4149f622eb5a1f48ae7a4bf16ff2a3
parent24fc22336273e919517cde2e8a81b5e4222f9e91 (diff)
downloadTwitterDataAnalytics-9c2f6a8112f6ad40789046dddd5c5ae6a79e213d.tar.gz
Close stream when stopping worker, English tweets only please...
-rw-r--r--src/io/StreamImpl.java16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/io/StreamImpl.java b/src/io/StreamImpl.java
index d72f926..ef61fe8 100644
--- a/src/io/StreamImpl.java
+++ b/src/io/StreamImpl.java
@@ -192,6 +192,7 @@ public class StreamImpl implements Stream {
private HttpURLConnection connect(String keywords) throws IOException {
String postData = "track=" + URLEncoder.encode(keywords, "UTF-8");
+ postData += "&language=en";
HttpURLConnection conn;
conn = (HttpURLConnection) new URL(STREAM_URL).openConnection();
conn.setRequestMethod("POST");
@@ -233,10 +234,13 @@ public class StreamImpl implements Stream {
@Override
public void run() {
InputStream is = null;
+ IOException run_error = null;
try {
is = connection.getInputStream();
parseMainLoop(wrapGzip(is));
} catch (IOException ex) {
+ run_error = ex;
+ } finally {
if (is != null) {
try {
is.close();
@@ -245,11 +249,13 @@ public class StreamImpl implements Stream {
}
}
connection.disconnect();
- // synchronize just in case the exception listener gets modified
- // while hell breaks lose.
- synchronized (listenerSync) {
- if (exceptionListener != null) {
- exceptionListener.exceptionGenerated(ex);
+ if (run_error != null) {
+ // synchronize just in case the exception listener gets
+ // modified while hell breaks lose.
+ synchronized (listenerSync) {
+ if (exceptionListener != null) {
+ exceptionListener.exceptionGenerated(run_error);
+ }
}
}
}