+
+ /**
+ * Prepare the cache (or clean it up).
+ * <p>
+ * The cache directory will always exist if this method succeed
+ *
+ * @param localCache
+ * the cache directory
+ * @param forceRefresh
+ * TRUE to force acache refresh (delete all files)
+ *
+ * @throw IOException if the cache cannot be created
+ */
+ private static void prepareCache(File localCache, boolean forceRefresh)
+ throws IOException {
+ // if needed
+ localCache.mkdirs();
+
+ if (!localCache.isDirectory()) {
+ throw new IOException("Cannot get a cache");
+ }
+
+ // delete local cached files (_*) or all files if forceRefresh
+ for (File f : localCache.listFiles()) {
+ if (forceRefresh || f.getName().startsWith("_")) {
+ IOUtils.deltree(f);
+ }
+ }
+ }