|
@@ -8,12 +8,15 @@ import org.lionsoul.ip2region.xdb.Searcher;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.InetAddress;
|
|
|
import java.net.URL;
|
|
|
import java.net.UnknownHostException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
@@ -55,11 +58,16 @@ public class IPUtils {
|
|
|
// use jar resource file file
|
|
|
|
|
|
try{
|
|
|
- ClassLoader classLoader = IPUtils.class.getClassLoader();
|
|
|
- if (classLoader.getResourceAsStream("ip/ip2region.xdb") == null) {
|
|
|
+ ClassLoader classLoader = IPUtils.class.getClassLoader();
|
|
|
+ if (classLoader.getResourceAsStream("ip/ip2region.xdb") == null) {
|
|
|
log.error("初始化IP地址索引失败");
|
|
|
- }
|
|
|
- log.info("初始化IP地址索引成功 (classpath)");
|
|
|
+ }
|
|
|
+ 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);
|
|
|
URL url = classLoader.getResource("ip/ip2region.xdb");
|
|
|
searcher = Searcher.newWithFileOnly(url.getPath());
|
|
|
} catch (IOException e) {
|