我有一個由IP地址組成的列。現在我需要將它們決議為國家/城市。
選擇IPUtils('199.999.999.999'),它回傳['Aisa', 'Hong Kong', 'xxx', 'Hong Kong']
INFO : 2021-09-08 18:51:10,817 Stage-2 map = 100%, reduce = 30%, Cumulative CPU 9074.06 sec
map = 100%,而reduce的進度每15分鐘增加1%。
UDF從專案的資源檔案夾中讀取檔案,所以它可能會重復地讀取檔案?udf顯示如下,希望得到任何幫助:
UDF從專案的資源檔案夾中讀取檔案,所以可能會重復讀取檔案?
public class IPUtil extends UDF {
public List<String> evaluate(String ip){
try{
ClassLoader classloader = Thread.currentThread().getContextClassLoader() 。
//I put the mmdb file in resource folder of the java project.
InputStream is = classloader.getResourceAsStream("GeoLite2-City.mmdb" ) 。
DatabaseReader reader = new DatabaseReader.Builder(is).build()。
InetAddress ipAddress = InetAddress.getByName(ip)。
CityResponse response = reader.city(ipAddress)。
Country country = response.getCountry()。
Subdivision subdivision = response.getMostSpecificSubdivision()。
City city = response.getCity()。
Continent continent = response.getContinent()。
List<String> list = new LinkedList<String>()。
list.add(continent.getNames().get("zh-CN"/span>))。
list.add(country.getNames().get("zh-CN"))。
list.add(subdivision.getNames().get("zh-CN"))。
list.add(city.getNames().get("zh-CN"))。
return串列。
} catch (UnknownHostException e) {
e.printStackTrace()。
return null;
} catch (IOException e) {
e.printStackTrace()。
return null;
} catch (GeoIp2Exception e) {
e.printStackTrace()。
return null;
}
}
@Test; }
public void test()throws Exception{
System.out.println(evaluation("175.45.20.138"))。
}
}
uj5u.com熱心網友回復:
移動這個
InputStream is = classloader. getResourceAsStream("GeoLite2-City.mmdb") 。
DatabaseReader reader = new DatabaseReader.Builder(is).build()。
到類的初始化。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/309438.html
標籤:
上一篇:云效研發協同服務相關協議條款
