1 | sS ipToCountry_dataSnippet = #1008743; |
2 | |
3 | static NavigableMap<Long, S> ipToCountry_data = new TreeMap; //synchroNavigableTreeMap(); |
4 | static Lock ipToCountry_lock = lock(); |
5 | |
6 | static S ipToCountry_old(S ip) null on exception { |
7 | long ipNum = ipToInt(trim(ip)); |
8 | lock ipToCountry_lock; |
9 | ipToCountry_init(); |
10 | Long key = ipToCountry_data.floorKey(ipNum); |
11 | ret key == null ? null : ipToCountry_data.get(key); |
12 | } |
13 | |
14 | static void ipToCountry_init() { |
15 | lock ipToCountry_lock; |
16 | if (nempty(ipToCountry_data)) ret; |
17 | |
18 | long start = 0; |
19 | for (S s : linesFromReader(utf8bufferedReader(gzInputStream(loadLibrary(ipToCountry_dataSnippet))))) { |
20 | L<S> l = splitAtSpace(s); |
21 | if (l(l) < 2) continue; |
22 | long diff = parseLong(first(l)); |
23 | S country = intern(last(l)); |
24 | start += diff; |
25 | ipToCountry_data.put(start, country); |
26 | } |
27 | } |
28 | |
29 | static void ipToCountry_clearCache() { |
30 | lock ipToCountry_lock; |
31 | ipToCountry_data.clear(); |
32 | } |
Began life as a copy of #1008738
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1032781 |
Snippet name: | ipToCountry_old - keeps data in memory (version with new database), returns ISO codes |
Eternal ID of this version: | #1032781/3 |
Text MD5: | ffa09cb0f42de2beefb36c1296ae99a5 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-06 04:00:32 |
Source code size: | 949 bytes / 32 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 134 / 149 |
Version history: | 2 change(s) |
Referenced in: | [show references] |