标签:color static display ddr exception tab ide int trace
日期:2019.11.15
博客期:117
星期五
这两天因为有课,其他的课程需要做实验,所以课下都在做其他科目的实验。
不过还是有新的进度的。
我研究了IP到城市的格式转换
1 public class IPUtil { 2 3 public static String getCityInfo(String ip){ 4 5 //db 6 //String dbPath = "data/ip2region.db"; 7 String dbPath = IPUtil.class.getResource("../data/ip2region.db").getPath(); 8 9 File file = new File(dbPath); 10 if ( file.exists() == false ) { 11 System.out.println("Error: Invalid ip2region.db file"); 12 } 13 14 //查询算法 15 int algorithm = DbSearcher.BTREE_ALGORITHM; //B-tree 16 //DbSearcher.BINARY_ALGORITHM //Binary 17 //DbSearcher.MEMORY_ALGORITYM //Memory 18 try { 19 DbConfig config = new DbConfig(); 20 DbSearcher searcher = new DbSearcher(config, dbPath); 21 22 //define the method 23 Method method = null; 24 switch ( algorithm ) 25 { 26 case DbSearcher.BTREE_ALGORITHM: 27 method = searcher.getClass().getMethod("btreeSearch", String.class); 28 break; 29 case DbSearcher.BINARY_ALGORITHM: 30 method = searcher.getClass().getMethod("binarySearch", String.class); 31 break; 32 case DbSearcher.MEMORY_ALGORITYM: 33 method = searcher.getClass().getMethod("memorySearch", String.class); 34 break; 35 } 36 37 DataBlock dataBlock = null; 38 if ( Util.isIpAddress(ip) == false ) { 39 System.out.println("Error: Invalid ip address"); 40 } 41 42 dataBlock = (DataBlock) method.invoke(searcher, ip); 43 44 return dataBlock.getRegion(); 45 46 } catch (Exception e) { 47 e.printStackTrace(); 48 } 49 50 return null; 51 } 52 53 public static void main(String[] args) throws Exception{ 54 System.out.println(getCityInfo("106.39.41.166")); 55 } 56 }
result.txt资源我已上传至我的资源文件里。
Hive的存储和MapReduce处理——数据清洗(Part3)
标签:color static display ddr exception tab ide int trace
原文地址:https://www.cnblogs.com/onepersonwholive/p/11869612.html