mirror of https://github.com/elunez/eladmin
1.修复ip2region 不会自动关闭连接问题
parent
33cdb7fea1
commit
7c5193a93d
|
@ -8,6 +8,7 @@ import org.lionsoul.ip2region.DbConfig;
|
|||
import org.lionsoul.ip2region.DbSearcher;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
@ -143,12 +144,13 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
* 根据ip获取详细地址
|
||||
*/
|
||||
public static String getCityInfo(String ip) {
|
||||
DbSearcher searcher = null;
|
||||
try {
|
||||
String path = "ip2region/ip2region.db";
|
||||
String name = "ip2region.db";
|
||||
DbConfig config = new DbConfig();
|
||||
File file = FileUtil.inputStreamToFile(new ClassPathResource(path).getStream(), name);
|
||||
DbSearcher searcher = new DbSearcher(config, file.getPath());
|
||||
searcher = new DbSearcher(config, file.getPath());
|
||||
Method method;
|
||||
method = searcher.getClass().getMethod("btreeSearch", String.class);
|
||||
DataBlock dataBlock;
|
||||
|
@ -161,6 +163,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
return address.equals(ElAdminConstant.REGION)?"内网IP":address;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(searcher!=null){
|
||||
try {
|
||||
searcher.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -185,4 +195,4 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
}
|
||||
return weekDays[w];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue