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)

static new TreeMap<Long, S> ipToCountry_data;

static S ipToCountry(S ip) {
  long ipNum = ipToInt(trim(ip));
  synchronized(ipToCountry_data) {
    ipToCountry_init();
    Long key = data.floorKey(ipNum);
    ret key == null ? null : data.get(key);
  }
}

static void ipToCountry_init() {
  synchronized(ipToCountry_data) {
    if (nempty(ipToCountry_data)) ret;
    
    for (S s : linesFromReader(utf8bufferedReader(lzmaInputStream(#1004343))))) {
      L<S> l = tok_splitAtComma_unquote(s);
      if (l(l) < 3) continue;
      long start = parseLong(first(l));
      long end = parseLong(second(l));
      S country = intern(l.get(4));
      ipToCountry_data.put(start, country);
    }
  }
}

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: 505 / 522
Referenced in: