From 9c2f6a8112f6ad40789046dddd5c5ae6a79e213d Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 1 May 2014 16:03:40 +0200 Subject: Close stream when stopping worker, English tweets only please... --- src/io/StreamImpl.java | 16 +++++++++++----- 1 file 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); + } } } } -- cgit v1.2.1