aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-12-18 21:59:38 +0100
committerChristian Schneppe <christian@pix-art.de>2016-12-18 21:59:38 +0100
commitd1af87e398066675c0b9d4ed39950b19f5f13d3d (patch)
tree341dd7cab11aeb98d69f5f5aa7deb54efcbaf43f /src/main
parent6815a788a3dc37e9294b944a26fa56e74e4f88d3 (diff)
fixed http resume
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
index 8c342e6f2..2e3021735 100644
--- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
@@ -282,16 +282,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.CONNECT_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) {
@@ -299,9 +301,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;