Changeset 3695 in josm
- Timestamp:
- 2010-12-03T19:11:39+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java
r3321 r3695 22 22 * Mirrors a file to a local file. 23 23 * <p> 24 * The file mirrored is only downloaded if it has been more than one daysince last download24 * The file mirrored is only downloaded if it has been more than 7 days since last download 25 25 */ 26 26 public class MirroredInputStream extends InputStream { … … 40 40 } 41 41 42 /** 43 * Get an inputstream from a given filename, url or internal resource. 44 * @param name can be 45 * - relative or absolute file name 46 * - file:///SOME/FILE the same as above 47 * - resource://SOME/FILE file from the classpath (usually in the current *.jar) 48 * - http://... a url. It will be cached on disk. 49 * @param destDir the destination directory for the cache file. only applies for urls. 50 * @param maxTime the maximum age of the cache file (in seconds) 51 * @throws IOException when the resource with the given name could not be retrieved 52 */ 42 53 public MirroredInputStream(String name, String destDir, long maxTime) throws IOException { 43 54 URL url; … … 126 137 if (!url.getProtocol().equals("file")) 127 138 { 128 String localPath = Main.pref.get("mirror." + url); 139 String prefKey = getPrefKey(url, destDir); 140 String localPath = Main.pref.get(prefKey); 129 141 if (localPath != null && localPath.length() > 0) 130 142 { … … 135 147 } 136 148 } 137 Main.pref.put( "mirror." + url, null);149 Main.pref.put(prefKey, null); 138 150 } 139 151 } catch (java.net.MalformedURLException e) {} 140 152 } 141 153 154 /** 155 * get preference key to store the location and age of the cached file. 156 * 2 resources that point to the same url, but that are to be stored in different 157 * directories will not share a cache file. 158 */ 159 private static String getPrefKey(URL url, String destDir) { 160 StringBuilder prefKey = new StringBuilder("mirror."); 161 if (destDir != null) { 162 String prefDir = Main.pref.getPreferencesDir(); 163 if (destDir.startsWith(prefDir)) { 164 destDir = destDir.substring(prefDir.length()); 165 } 166 prefKey.append(destDir); 167 prefKey.append("."); 168 } 169 prefKey.append(url.toString()); 170 return prefKey.toString(); 171 } 172 142 173 private File checkLocal(URL url, String destDir, long maxTime) throws IOException { 143 String localPath = Main.pref.get("mirror." + url); 174 String prefKey = getPrefKey(url, destDir); 175 String localPath = Main.pref.get(prefKey); 144 176 File file = null; 145 177 if (localPath != null && localPath.length() > 0) { … … 196 228 file = new File(destDir, localPath); 197 229 destDirFile.renameTo(file); 198 Main.pref.put( "mirror." + url, System.currentTimeMillis() + ";" + file);230 Main.pref.put(prefKey, System.currentTimeMillis() + ";" + file); 199 231 } 200 232
Note:
See TracChangeset
for help on using the changeset viewer.