` static {
/*
* 此文件为独享 ,不必关闭
*/
String path = "ip2region/ip2region.xdb";
String name = "ip2region.xdb";
try {
byte[] cBuff = Searcher.loadContentFromFile(FileUtil.inputStreamToFile(new ClassPathResource(path).getInputStream(), name).getPath());
// File file = FileUtil.inputStreamToFile(new ClassPathResource(path).getInputStream(), name);
// dbSearcher = Searcher.newWithBuffer(FileUtil.getByte(file));
dbSearcher = Searcher.newWithBuffer(cBuff);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
public static String getLocalCityInfo(String ip) {
String region = null;
try {
System.out.println(ip);
region = dbSearcher.search(ip);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
System.out.println(region);
if(region!=null){
String address = region.replace("0|", "");
char symbol = '|';
if (address.charAt(address.length() - 1) == symbol) {
address = address.substring(0, address.length() - 1);
}
return address.equals("内网IP|内网IP") ? "内网IP" : address;
}
return "";
}
public static void main(String[] args) {
System.out.println(getLocalCityInfo("1.80.0.0"));
// System.out.println(getLocalCityInfo("101.204.66.178"));
}
`
爆出 arraycopy: source index -15407511 out of bounds for byte[17498059]
以前都没有这样的问题