diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-12-06 23:27:29 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-12-06 23:27:29 +0100 |
commit | 1739af2a41d4f4262402043641d1738f6a5b3fb7 (patch) | |
tree | dc395ff0b35c783156d0cc546fc9604606710ef4 /src/main | |
parent | b879fb375368f773448ddeba77c97090df1aacc8 (diff) |
fixed http resume
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index 87f62706..356856dc 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -273,16 +273,18 @@ public class HttpDownloadConnection implements Transferable { } connection.setRequestProperty("User-Agent",mXmppConnectionService.getIqGenerator().getIdentityName()); final boolean tryResume = file.exists() && file.getKey() == null; + long resumeSize = 0; if (tryResume) { Log.d(Config.LOGTAG,"http download trying resume"); - long size = file.getSize(); - connection.setRequestProperty("Range", "bytes="+size+"-"); + resumeSize = file.getSize(); + connection.setRequestProperty("Range", "bytes="+resumeSize+"-"); } connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000); connection.setReadTimeout(Config.SOCKET_TIMEOUT * 1000); connection.connect(); is = new BufferedInputStream(connection.getInputStream()); - boolean serverResumed = "bytes".equals(connection.getHeaderField("Accept-Ranges")); + final String contentRange = connection.getHeaderField("Content-Range"); + boolean serverResumed = tryResume && contentRange != null && contentRange.startsWith("bytes "+resumeSize+"-"); long transmitted = 0; long expected = file.getExpectedSize(); if (tryResume && serverResumed) { @@ -290,9 +292,14 @@ public class HttpDownloadConnection implements Transferable { transmitted = file.getSize(); updateProgress((int) ((((double) transmitted) / expected) * 100)); os = AbstractConnectionManager.createAppendedOutputStream(file); + if (os == null) { + throw new FileWriterException(); + } } else { file.getParentFile().mkdirs(); - file.createNewFile(); + if (!file.exists() && !file.createNewFile()) { + throw new FileWriterException(); + } os = AbstractConnectionManager.createOutputStream(file, true); } int count; |