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

40
LINES

< > BotCompany Repo | #1002087 // DiskTextMap

JavaX fragment (include)

1  
// possible problem: case of keys (Windows only)
2  
static class DiskTextMap {
3  
  File dir;
4  
  
5  
  *(S dirName) {
6  
    dir = getProgramFile(dirName);
7  
    dir.mkdirs();
8  
  }
9  
  
10  
  void clear() {
11  
    deleteAllFilesWithSuffix(dir, ".text");
12  
  }
13  
  
14  
  S get(S key) {
15  
    ret loadTextFile(getFile(key));
16  
  }
17  
  
18  
  File getFile(S key) {
19  
    ret new File(dir, urlencode(key) + ".text");
20  
  }
21  
  
22  
  void remove(S key) {
23  
    getFile(key).delete();
24  
  }
25  
  
26  
  void put(S key, S value) {
27  
    saveTextFile(getFile(key), value);
28  
  }
29  
  
30  
  int size() {
31  
    ret l(listFilesWithSuffix(dir, ".text"));
32  
  }
33  
  
34  
  Set<S> keySet() {
35  
    new TreeSet<S> set;
36  
    for (File f : listFilesWithSuffix(dir, ".text"))
37  
      set.add(dropSuffix(".text", f.getName()));
38  
    ret set;
39  
  }
40  
}

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: 584 / 1510
Referenced in: [show references]