mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-22 16:56:16 +00:00
Replaced Thread.sleep by TimeUnit.SECONDS.sleep and colleagues. Doesn't change the way the code works and still uses Thread.sleep internally, but now the code is much easier to read.
This commit is contained in:
parent
517e5b68ed
commit
2ccb0cea9f
@ -45,6 +45,7 @@ import java.util.List;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ public class DownloadManager {
|
|||||||
System.out.println("");
|
System.out.println("");
|
||||||
System.out.println("Telegram took too long to respond to our request.");
|
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.");
|
System.out.println("I'm going to wait a minute and then try again.");
|
||||||
try { Thread.sleep(60*1000); } catch(InterruptedException e2) {}
|
try { TimeUnit.MINUTES.sleep(1); } catch(InterruptedException e2) {}
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
}
|
}
|
||||||
} while (!completed);
|
} while (!completed);
|
||||||
@ -185,7 +186,7 @@ public class DownloadManager {
|
|||||||
db.saveUsers(response.getUsers());
|
db.saveUsers(response.getUsers());
|
||||||
logger.trace("Sleeping");
|
logger.trace("Sleeping");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(Config.DELAY_AFTER_GET_MESSAGES);
|
TimeUnit.MILLISECONDS.sleep(Config.DELAY_AFTER_GET_MESSAGES);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
logger.debug("Finished.");
|
logger.debug("Finished.");
|
||||||
@ -212,7 +213,7 @@ public class DownloadManager {
|
|||||||
System.out.println("");
|
System.out.println("");
|
||||||
System.out.println("Telegram took too long to respond to our request.");
|
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.");
|
System.out.println("I'm going to wait a minute and then try again.");
|
||||||
try { Thread.sleep(60*1000); } catch(InterruptedException e2) {}
|
try { TimeUnit.MINUTES.sleep(1); } catch(InterruptedException e2) {}
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
}
|
}
|
||||||
} while (!completed);
|
} while (!completed);
|
||||||
@ -302,7 +303,7 @@ public class DownloadManager {
|
|||||||
|
|
||||||
fos.write(response.getBytes().getData());
|
fos.write(response.getBytes().getData());
|
||||||
fos.flush();
|
fos.flush();
|
||||||
try { Thread.sleep(Config.DELAY_AFTER_GET_FILE); } catch(InterruptedException e) {}
|
try { TimeUnit.MILLISECONDS.sleep(Config.DELAY_AFTER_GET_FILE); } catch(InterruptedException e) {}
|
||||||
} while(offset < size && response.getBytes().getData().length>0);
|
} while(offset < size && response.getBytes().getData().length>0);
|
||||||
fos.close();
|
fos.close();
|
||||||
if (offset < size) {
|
if (offset < size) {
|
||||||
@ -322,7 +323,7 @@ public class DownloadManager {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.debug("Exception during move. rename_tries: {}. Exception: {}", rename_tries, e);
|
logger.debug("Exception during move. rename_tries: {}. Exception: {}", rename_tries, e);
|
||||||
last_exception = e;
|
last_exception = e;
|
||||||
try { Thread.sleep(Config.RENAMING_DELAY); } catch (InterruptedException e2) {}
|
try { TimeUnit.MILLISECONDS.sleep(Config.RENAMING_DELAY); } catch (InterruptedException e2) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (last_exception != null) {
|
if (last_exception != null) {
|
||||||
|
@ -19,6 +19,7 @@ import com.github.badoualy.telegram.tl.exception.RpcErrorException;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
@ -59,7 +60,7 @@ public class Utils {
|
|||||||
"Ctrl+C. You can restart me at any time and I will just continue to download your\n" +
|
"Ctrl+C. You can restart me at any time and I will just continue to download your\n" +
|
||||||
"messages and media. But be advised that just restarting me is not going to change\n" +
|
"messages and media. But be advised that just restarting me is not going to change\n" +
|
||||||
"the fact that Telegram won't talk to me until then.");
|
"the fact that Telegram won't talk to me until then.");
|
||||||
try { Thread.sleep((delay + 1) * 1000); } catch(InterruptedException e2) {}
|
try { TimeUnit.SECONDS.sleep(delay + 1); } catch(InterruptedException e2) {}
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user