|
@@ -7,16 +7,14 @@ import lombok.extern.log4j.Log4j2;
|
|
import org.lionsoul.ip2region.xdb.Searcher;
|
|
import org.lionsoul.ip2region.xdb.Searcher;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
|
|
+import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.InetAddress;
|
|
import java.net.InetAddress;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.net.UnknownHostException;
|
|
import java.net.UnknownHostException;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
-import java.nio.file.Files;
|
|
|
|
-import java.nio.file.Path;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -58,18 +56,21 @@ public class IPUtils {
|
|
// use jar resource file file
|
|
// use jar resource file file
|
|
|
|
|
|
try{
|
|
try{
|
|
- ClassLoader classLoader = IPUtils.class.getClassLoader();
|
|
|
|
- if (classLoader.getResourceAsStream("ip/ip2region.xdb") == null) {
|
|
|
|
- log.error("初始化IP地址索引失败");
|
|
|
|
- }
|
|
|
|
- log.info("初始化IP地址索引成功 (classpath)");
|
|
|
|
- InputStream is = classLoader.getResourceAsStream("ip/ip2region.xdb");
|
|
|
|
- byte[] cBuff = is.readAllBytes();
|
|
|
|
- Path tmp = Files.createTempFile("ip2region", ".xdb");
|
|
|
|
- Files.write(tmp, cBuff);
|
|
|
|
|
|
+// ClassLoader classLoader =this.getClass().getClassLoader();
|
|
|
|
+// if (classLoader.getResourceAsStream("ip/ip2region.xdb") == null) {
|
|
|
|
+// log.error("初始化IP地址索引失败");
|
|
|
|
+// }
|
|
|
|
+// log.info("初始化IP地址索引成功 (classpath)");
|
|
|
|
+// InputStream is = classLoader.getResourceAsStream("ip/ip2region.xdb");
|
|
|
|
+// byte[] cBuff = is.readAllBytes();
|
|
|
|
+// Path tmp = Files.createTempFile("ip2region", ".xdb");
|
|
|
|
+// Files.write(tmp, cBuff);
|
|
// subtleSetDeleteOnExit(tmp);
|
|
// subtleSetDeleteOnExit(tmp);
|
|
- URL url = classLoader.getResource("ip/ip2region.xdb");
|
|
|
|
- searcher = Searcher.newWithFileOnly(url.getPath());
|
|
|
|
|
|
+ // 获取程序目录下的ip文件
|
|
|
|
+
|
|
|
|
+ File xdb = new File("./ip/ip2region_v4.xdb");
|
|
|
|
+// URL url = classLoader.getResource("ip/ip2region_v4.xdb");
|
|
|
|
+ searcher = Searcher.newWithFileOnly(xdb.getPath());
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
log.error("初始化IP地址索引失败", e);
|
|
log.error("初始化IP地址索引失败", e);
|
|
throw e;
|
|
throw e;
|