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

25
LINES

< > BotCompany Repo | #1008744 // ipToCountry - keeps data in memory (version with bad database)

JavaX fragment (include)

1  
static new TreeMap<Long, S> ipToCountry_data;
2  
3  
static S ipToCountry(S ip) {
4  
  long ipNum = ipToInt(trim(ip));
5  
  synchronized(ipToCountry_data) {
6  
    ipToCountry_init();
7  
    Long key = data.floorKey(ipNum);
8  
    ret key == null ? null : data.get(key);
9  
  }
10  
}
11  
12  
static void ipToCountry_init() {
13  
  synchronized(ipToCountry_data) {
14  
    if (nempty(ipToCountry_data)) ret;
15  
    
16  
    for (S s : linesFromReader(utf8bufferedReader(lzmaInputStream(#1004343))))) {
17  
      L<S> l = tok_splitAtComma_unquote(s);
18  
      if (l(l) < 3) continue;
19  
      long start = parseLong(first(l));
20  
      long end = parseLong(second(l));
21  
      S country = intern(l.get(4));
22  
      ipToCountry_data.put(start, country);
23  
    }
24  
  }
25  
}

Author comment

Began life as a copy of #1008738

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: #1008744
Snippet name: ipToCountry - keeps data in memory (version with bad database)
Eternal ID of this version: #1008744/1
Text MD5: 17630beb6c44bc2d6c11741f99121e5c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-31 13:41:31
Source code size: 721 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 445 / 455
Referenced in: [show references]