fix dividing by zero while loading empty file (#26)

This commit is contained in:
Alexey Danilov
2015-11-06 13:43:08 +03:00
parent a270460c8d
commit 0aad13f118
5 changed files with 35 additions and 9 deletions

View File

@@ -91,7 +91,7 @@ public class HttpProxyCacheServer {
private void makeSureServerWorks() {
int maxPingAttempts = 3;
int delay = 200;
int delay = 300;
int pingAttempts = 0;
while (pingAttempts < maxPingAttempts) {
try {
@@ -107,7 +107,7 @@ public class HttpProxyCacheServer {
pingAttempts++;
delay *= 2;
}
Log.e(LOG_TAG, "Shutdown server… Error pinging server [attempt: " + pingAttempts + ", timeout: " + delay + "]. " +
Log.e(LOG_TAG, "Shutdown server… Error pinging server [attempts: " + pingAttempts + ", max timeout: " + delay / 2 + "]. " +
"If you see this message, please, email me danikula@gmail.com");
shutdown();
}

View File

@@ -100,10 +100,11 @@ class ProxyCache {
}
}
protected void onCacheAvailable(long cacheAvailable, long sourceAvailable) {
int percents = (int) (cacheAvailable * 100 / sourceAvailable);
protected void onCacheAvailable(long cacheAvailable, long sourceLength) {
boolean zeroLengthSource = sourceLength == 0;
int percents = zeroLengthSource ? 100 : (int) (cacheAvailable * 100 / sourceLength);
boolean percentsChanged = percents != percentsAvailable;
boolean sourceLengthKnown = sourceAvailable >= 0;
boolean sourceLengthKnown = sourceLength >= 0;
if (sourceLengthKnown && percentsChanged) {
onCachePercentsAvailableChanged(percents);
}