From 84984ddc203c7f7e6b08bd902a733ed2783e5624 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Tue, 5 Jul 2016 14:09:31 +0200 Subject: [PATCH] Prepared to catch TimeoutExceptions and restart the download, if necessary. --- .../telegram_backup/DownloadManager.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java index dd01935..052dee4 100644 --- a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java +++ b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java @@ -21,6 +21,7 @@ import java.io.FileOutputStream; import java.util.ArrayList; import java.util.LinkedList; import java.net.URL; +import java.util.concurrent.TimeoutException; import org.apache.commons.io.FileUtils; @@ -60,11 +61,18 @@ class DownloadManager { } else { throw e; } + } catch (TimeoutException e) { + completed = false; + System.out.println(""); + System.out.println("Telegram took too long to respond to our request."); + System.out.println("I'm going to wait a minute and then try again."); + try { Thread.sleep(60*1000); } catch(InterruptedException e2) {} + System.out.println(""); } } while (!completed); } - public void _downloadMessages(Integer limit) throws RpcErrorException, IOException { + public void _downloadMessages(Integer limit) throws RpcErrorException, IOException, TimeoutException { System.out.println("Downloading most recent dialog... "); int max_message_id = client.messagesGetDialogs( 0, @@ -157,14 +165,22 @@ class DownloadManager { System.out.println("messages and media. But be advised that just restarting me is not going to change"); System.out.println("the fact that Telegram won't talk to me until then."); try { Thread.sleep((delay + 60) * 1000); } catch(InterruptedException e2) {} + System.out.println(""); } else { throw e; } + } catch (TimeoutException e) { + completed = false; + System.out.println(""); + System.out.println("Telegram took too long to respond to our request."); + System.out.println("I'm going to wait a minute and then try again."); + try { Thread.sleep(60*1000); } catch(InterruptedException e2) {} + System.out.println(""); } } while (!completed); } - private void _downloadMedia() throws RpcErrorException, IOException { + private void _downloadMedia() throws RpcErrorException, IOException, TimeoutException { LinkedList messages = this.db.getMessagesWithMedia(); prog.onMediaDownloadStart(messages.size()); for (TLMessage msg : messages) {