]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/gui/map/DiskTileCacher.java
Version 16, February 2014
[GpsPrune.git] / tim / prune / gui / map / DiskTileCacher.java
index 350b3b4b1cdb1f2bbc53ff9f98accadbb1d0bbe5..459b140f2c0108b9adf35805bf1b0451d3f80811 100644 (file)
@@ -63,7 +63,9 @@ public class DiskTileCacher implements Runnable
                                try {
                                        image = Toolkit.getDefaultToolkit().createImage(tileFile.getAbsolutePath());
                                }
-                               catch (Exception e) {}
+                               catch (Exception e) {
+                                       System.err.println("createImage: " + e.getClass().getName() + " _ " + e.getMessage());
+                               }
                        }
                }
                return image;
@@ -110,7 +112,12 @@ public class DiskTileCacher implements Runnable
        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
        }
 
        /**
@@ -125,7 +132,7 @@ public class DiskTileCacher implements Runnable
                // 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;}
                        }