diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-03-11 14:30:26 +0100 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-03-11 14:30:26 +0100 |
commit | cdf73fd1f7121cd2333b0b1819c56e797f15666f (patch) | |
tree | e68113596f7710327b214f8dda17ab1da24f7830 /src | |
parent | 35f53c74ebcd8a7c970c048f7ec39f9e7de1a552 (diff) | |
download | AntennaPod-cdf73fd1f7121cd2333b0b1819c56e797f15666f.zip |
Shutdown connection manager after download
Diffstat (limited to 'src')
-rw-r--r-- | src/de/danoeh/antennapod/service/download/HttpDownloader.java | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/de/danoeh/antennapod/service/download/HttpDownloader.java b/src/de/danoeh/antennapod/service/download/HttpDownloader.java index ec2b991b4..07998be0b 100644 --- a/src/de/danoeh/antennapod/service/download/HttpDownloader.java +++ b/src/de/danoeh/antennapod/service/download/HttpDownloader.java @@ -54,9 +54,10 @@ public class HttpDownloader extends Downloader { HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT); HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); HttpClientParams.setRedirecting(params, true); - + // Workaround for broken URLs in redirection - ((AbstractHttpClient)httpClient).setRedirectHandler(new APRedirectHandler()); + ((AbstractHttpClient) httpClient) + .setRedirectHandler(new APRedirectHandler()); return httpClient; } @@ -79,7 +80,8 @@ public class HttpDownloader extends Downloader { File destination = new File(status.getFeedFile() .getFile_url()); if (!destination.exists()) { - connection = AndroidHttpClient.getUngzippedContent(httpEntity); + connection = AndroidHttpClient + .getUngzippedContent(httpEntity); InputStream in = new BufferedInputStream(connection); out = new BufferedOutputStream(new FileOutputStream( destination)); @@ -148,6 +150,9 @@ public class HttpDownloader extends Downloader { } finally { IOUtils.closeQuietly(connection); IOUtils.closeQuietly(out); + if (httpClient != null) { + httpClient.getConnectionManager().shutdown(); + } } } @@ -178,16 +183,20 @@ public class HttpDownloader extends Downloader { status.setCancelled(true); cleanup(); } - + /** Deletes unfinished downloads. */ private void cleanup() { - if (status != null && status.getFeedFile() != null && status.getFeedFile().getFile_url() != null) { + if (status != null && status.getFeedFile() != null + && status.getFeedFile().getFile_url() != null) { File dest = new File(status.getFeedFile().getFile_url()); if (dest.exists()) { boolean rc = dest.delete(); - if (AppConfig.DEBUG) Log.d(TAG, "Deleted file " + dest.getName() + "; Result: " + rc); + if (AppConfig.DEBUG) + Log.d(TAG, "Deleted file " + dest.getName() + "; Result: " + + rc); } else { - if (AppConfig.DEBUG) Log.d(TAG, "cleanup() didn't delete file: does not exist."); + if (AppConfig.DEBUG) + Log.d(TAG, "cleanup() didn't delete file: does not exist."); } } } |