Shutdown connection manager after download

This commit is contained in:
daniel oeh 2013-03-11 14:30:26 +01:00
parent 35f53c74eb
commit cdf73fd1f7
1 changed files with 16 additions and 7 deletions

View File

@ -56,7 +56,8 @@ public class HttpDownloader extends Downloader {
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();
}
}
}
@ -181,13 +186,17 @@ public class HttpDownloader extends Downloader {
/** 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.");
}
}
}