_url = inUrl;
_file = inFile;
_observer = inObserver;
- new Thread(this).start();
}
/**
try {
image = Toolkit.getDefaultToolkit().createImage(tileFile.getAbsolutePath());
}
- catch (Exception e) {}
+ catch (Exception e) {
+ System.err.println("createImage: " + e.getClass().getName() + " _ " + e.getMessage());
+ }
}
}
return image;
// Start a new thread to load the image if necessary
if ((dir.exists() || dir.mkdirs()) && dir.canWrite())
{
- new DiskTileCacher(inUrl, tileFile, inObserver);
+ new Thread(new DiskTileCacher(inUrl, tileFile, inObserver)).start();
return true;
}
return false; // couldn't write the file
private static boolean isBeingLoaded(File inFile)
{
File tempFile = new File(inFile.getAbsolutePath() + ".temp");
- return tempFile.exists();
+ if (!tempFile.exists()) {
+ return false;
+ }
+ // File exists, so check if it was created recently
+ final long fileAge = System.currentTimeMillis() - tempFile.lastModified();
+ return fileAge < 1000000L; // overwrite if the temp file is still there after 1000s
}
/**
// Use a synchronized block across all threads to make sure this url is only fetched once
synchronized (DiskTileCacher.class)
{
- if (tempFile.exists()) {return;}
+ if (tempFile.exists()) {tempFile.delete();}
try {
if (!tempFile.createNewFile()) {return;}
}