}
private static boolean mirrorIsUpToDate(Mirror mirror, String id) throws TvBrowserException {
// Load the lastupdate file and parse it
final String url = mirror.getUrl() + (mirror.getUrl().endsWith("/") ? "" : "/") + id + "_lastupdate";
Date lastupdated;
mMirrorDownloadRunning = true;
mMirrorDownloadData = null;
mDownloadException = false;
mLog.info("Loading MirrorDate from " + url);
new Thread(new Runnable() {
public void run() {
try {
mMirrorDownloadData = IOUtilities.loadFileFromHttpServer(new URL(url), 60000);
} catch (Exception e) {
mDownloadException = true;
}
mMirrorDownloadRunning = false;
};
}, "Load mirror date from "+url).start();
int num = 0;
// Wait till second Thread is finished or 15000 ms reached
while ((mMirrorDownloadRunning) && (num < 150)) {
num++;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (mMirrorDownloadRunning || mMirrorDownloadData == null || mDownloadException) {
mLog.info("Server " + url +" is down!");
return false;
}
try {
// Parse is. E.g.: '2003-10-09 11:48:45'
String asString = new String(mMirrorDownloadData);
if (asString.length() > 10) {
int year = Integer.parseInt(asString.substring(0, 4));
int month = Integer.parseInt(asString.substring(5, 7));
int day = Integer.parseInt(asString.substring(8, 10));
lastupdated = new Date(year, month, day);
mLog.info("Done !");
return lastupdated.compareTo(new Date().addDays(-MAX_LAST_UPDATE_DAYS)) >= 0;
}
}catch(NumberFormatException parseException) {
mLog.info("The file on the server has the wrong format!");
}