diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java index 376ddb0cb..f091c9dad 100644 --- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java @@ -28,6 +28,7 @@ import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.services.AbstractConnectionManager; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.CryptoHelper; +import de.pixart.messenger.utils.FileWriterException; public class HttpDownloadConnection implements Transferable { @@ -105,7 +106,7 @@ public class HttpDownloadConnection implements Transferable { || this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL) && this.file.getKey() == null) { this.message.setEncryption(Message.ENCRYPTION_NONE); - } + } checkFileSize(interactive); } catch (MalformedURLException e) { this.cancel(); @@ -147,16 +148,12 @@ public class HttpDownloadConnection implements Transferable { mXmppConnectionService.updateConversationUi(); } - private class WriteException extends IOException { - - } - private void showToastForException(Exception e) { 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) { + } else if (e instanceof FileWriterException) { mXmppConnectionService.showErrorToastInUi(R.string.download_failed_could_not_write_file); } else if (!(e instanceof CancellationException)) { mXmppConnectionService.showErrorToastInUi(R.string.download_failed_file_not_found); @@ -220,8 +217,8 @@ public class HttpDownloadConnection implements Transferable { if (connection instanceof HttpsURLConnection) { mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive); } - connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000); - connection.setReadTimeout(Config.CONNECT_TIMEOUT * 1000); + connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000); + connection.setReadTimeout(Config.CONNECT_TIMEOUT * 1000); connection.connect(); String contentLength = connection.getHeaderField("Content-Length"); connection.disconnect(); @@ -290,8 +287,8 @@ public class HttpDownloadConnection implements Transferable { long size = file.getSize(); connection.setRequestProperty("Range", "bytes="+size+"-"); } - connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000); - connection.setReadTimeout(Config.CONNECT_TIMEOUT * 1000); + 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")); @@ -314,7 +311,7 @@ public class HttpDownloadConnection implements Transferable { try { os.write(buffer, 0, count); } catch (IOException e) { - throw new WriteException(); + throw new FileWriterException(); } updateProgress((int) ((((double) transmitted) / expected) * 100)); if (canceled) { @@ -324,7 +321,7 @@ public class HttpDownloadConnection implements Transferable { try { os.flush(); } catch (IOException e) { - throw new WriteException(); + throw new FileWriterException(); } } catch (CancellationException | IOException e) { throw e; |