From b3686c84170b097a6e5b120e6231fe574f017aff Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 7 Nov 2015 13:06:58 +0100 Subject: [PATCH] Fix download file --- .../plus/download/DownloadFileHelper.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java index 525ad45592..c93d70cd81 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java @@ -313,15 +313,18 @@ public class DownloadFileHelper { throws IOException { targetFile.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(targetFile); - int read; - byte[] buffer = new byte[BUFFER_SIZE]; - int remaining = length; - while ((read = toRead.read(buffer)) != -1) { - out.write(buffer, 0, read); - remaining -= countIS.getAndClearReadCount(); - progress.remaining(remaining / 1024); + try { + int read; + byte[] buffer = new byte[BUFFER_SIZE]; + int remaining = length; + while ((read = toRead.read(buffer)) != -1) { + out.write(buffer, 0, read); + remaining -= countIS.getAndClearReadCount(); + progress.remaining(remaining / 1024); + } + } finally { + out.close(); } - out.close(); targetFile.setLastModified(de.dateModified); }