Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Commit

Permalink
Replaced Thread.sleep by TimeUnit.SECONDS.sleep and colleagues. Doesn…
Browse files Browse the repository at this point in the history
…'t change the way the code works and still uses Thread.sleep internally, but now the code is much easier to read.
  • Loading branch information
fabianonline committed Sep 20, 2016
1 parent 517e5b6 commit 2ccb0ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.Random;
import java.net.URL;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

Expand Down Expand Up @@ -84,7 +85,7 @@ public void downloadMessages(Integer limit) throws RpcErrorException, IOExceptio
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) {}
try { TimeUnit.MINUTES.sleep(1); } catch(InterruptedException e2) {}
System.out.println("");
}
} while (!completed);
Expand Down Expand Up @@ -185,7 +186,7 @@ private void downloadMessages(List<Integer> ids) throws RpcErrorException, IOExc
db.saveUsers(response.getUsers());
logger.trace("Sleeping");
try {
Thread.sleep(Config.DELAY_AFTER_GET_MESSAGES);
TimeUnit.MILLISECONDS.sleep(Config.DELAY_AFTER_GET_MESSAGES);
} catch (InterruptedException e) {}
}
logger.debug("Finished.");
Expand All @@ -212,7 +213,7 @@ public void downloadMedia() throws RpcErrorException, IOException {
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) {}
try { TimeUnit.MINUTES.sleep(1); } catch(InterruptedException e2) {}
System.out.println("");
}
} while (!completed);
Expand Down Expand Up @@ -302,7 +303,7 @@ private static boolean downloadFileFromDc(TelegramClient client, String target,

fos.write(response.getBytes().getData());
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);
fos.close();
if (offset < size) {
Expand All @@ -322,7 +323,7 @@ private static boolean downloadFileFromDc(TelegramClient client, String target,
} catch (IOException e) {
logger.debug("Exception during move. rename_tries: {}. Exception: {}", rename_tries, 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) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/fabianonline/telegram_backup/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.File;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.TimeUnit;
import com.google.gson.*;
import java.net.URL;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -59,7 +60,7 @@ static void obeyFloodWaitException(RpcErrorException e) throws RpcErrorException
"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" +
"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("");
}

Expand Down

0 comments on commit 2ccb0ce

Please sign in to comment.