aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-06-02 21:37:52 +0200
committerDaniel Gultsch <daniel@gultsch.de>2016-06-02 21:37:52 +0200
commit583aba1b442a1b41a11442d51dc31c5d1f18617e (patch)
treea5a3621639be0a5caca096bec83a15c2ca24f2e2 /src/main/java/eu/siacs
parent594aab56dbffab5eec5d922f30cec3262752ceb4 (diff)
print specific toast when download failed because of write error
Diffstat (limited to 'src/main/java/eu/siacs')
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
index d23cb71a3..cffed30ae 100644
--- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
+++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
@@ -140,12 +140,18 @@ public class HttpDownloadConnection implements Transferable {
mXmppConnectionService.updateConversationUi();
}
+ private class WriteException extends IOException {
+
+ }
+
private void showToastForException(Exception e) {
e.printStackTrace();
if (e instanceof java.net.UnknownHostException) {
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_server_not_found);
} else if (e instanceof java.net.ConnectException) {
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_could_not_connect);
+ } else if (e instanceof WriteException) {
+ mXmppConnectionService.showErrorToastInUi(R.string.download_failed_could_not_write_file);
} else if (!(e instanceof CancellationException)) {
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_file_not_found);
}
@@ -284,11 +290,15 @@ public class HttpDownloadConnection implements Transferable {
file.createNewFile();
os = AbstractConnectionManager.createOutputStream(file, true);
}
- int count = -1;
+ int count;
byte[] buffer = new byte[1024];
while ((count = is.read(buffer)) != -1) {
transmitted += count;
- os.write(buffer, 0, count);
+ try {
+ os.write(buffer, 0, count);
+ } catch (IOException e) {
+ throw new WriteException();
+ }
updateProgress((int) ((((double) transmitted) / expected) * 100));
if (canceled) {
throw new CancellationException();