Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #1002087 // DiskTextMap

JavaX fragment (include)

// possible problem: case of keys (Windows only)
static class DiskTextMap {
  File dir;
  
  *(S dirName) {
    dir = getProgramFile(dirName);
    dir.mkdirs();
  }
  
  void clear() {
    deleteAllFilesWithSuffix(dir, ".text");
  }
  
  S get(S key) {
    ret loadTextFile(getFile(key));
  }
  
  File getFile(S key) {
    ret new File(dir, urlencode(key) + ".text");
  }
  
  void remove(S key) {
    getFile(key).delete();
  }
  
  void put(S key, S value) {
    saveTextFile(getFile(key), value);
  }
  
  int size() {
    ret l(listFilesWithSuffix(dir, ".text"));
  }
  
  Set<S> keySet() {
    new TreeSet<S> set;
    for (File f : listFilesWithSuffix(dir, ".text"))
      set.add(dropSuffix(".text", f.getName()));
    ret set;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002087
Snippet name: DiskTextMap
Eternal ID of this version: #1002087/1
Text MD5: a88c50ee2d93fe01dcc4b338437a3eea
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-17 20:41:54
Source code size: 779 bytes / 40 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 654 / 1588
Referenced in: [show references]