1 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
5 import org.ibex.util.*;
6 import org.bouncycastle.util.encoders.Base64;
8 /** Manages access to ~/.ibex */
9 public class LocalStorage {
11 static String ibexDirName = System.getProperty("user.home") + java.io.File.separatorChar + ".ibex";
13 static java.io.File ibexDir = null;
14 static java.io.File cacheDir = null;
18 ibexDir = new java.io.File(ibexDirName);
19 if (!ibexDir.mkdirs()) ibexDir = null;
21 cacheDir = new java.io.File(ibexDirName + java.io.File.separatorChar + "cache");
22 if (!cacheDir.mkdirs()) cacheDir = null;
23 } catch (Exception e) {
24 Log.warn(LocalStorage.class, "unable to create cache directory " +
25 ibexDirName + java.io.File.separatorChar + "cache");
27 } catch (Exception e) {
28 Log.warn(LocalStorage.class, "unable to create ibex directory " + ibexDirName);
32 // FEATURE: we ought to be able to do stuff like sha1-checking and date checking on cached resources
33 public static class Cache {
35 private static void delTree(java.io.File f) throws IOException {
36 if (f.isDirectory()) {
37 String[] s = f.list();
38 for(int i=0; i<s.length; i++)
39 delTree(new java.io.File(f.getPath() + java.io.File.separatorChar + s[i]));
44 public static void flush() throws IOException {
49 public static java.io.File getCacheFileForKey(String key) {
50 // FEATURE: be smarter here
51 return new java.io.File(cacheDir.getPath() + File.separatorChar + new String(Base64.encode(key.getBytes())));