|
@@ -56,6 +56,10 @@ public class IPUtils {
|
|
externalPath = System.getenv("IP2REGION_DB_PATH");
|
|
externalPath = System.getenv("IP2REGION_DB_PATH");
|
|
}
|
|
}
|
|
if (externalPath != null && !externalPath.trim().isEmpty()) {
|
|
if (externalPath != null && !externalPath.trim().isEmpty()) {
|
|
|
|
+ java.nio.file.Path p = java.nio.file.Paths.get(externalPath.trim());
|
|
|
|
+ Long size = null;
|
|
|
|
+ try { size = java.nio.file.Files.exists(p) ? java.nio.file.Files.size(p) : null; } catch (Exception ignore) {}
|
|
|
|
+ log.info("ip2region准备使用外部文件: path={}, exists={}, size={}", externalPath, java.nio.file.Files.exists(p), size);
|
|
searcher = Searcher.newWithFileOnly(externalPath.trim());
|
|
searcher = Searcher.newWithFileOnly(externalPath.trim());
|
|
log.info("ip2region初始化成功 (external path: {})", externalPath);
|
|
log.info("ip2region初始化成功 (external path: {})", externalPath);
|
|
return;
|
|
return;
|
|
@@ -69,9 +73,13 @@ public class IPUtils {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
byte[] cBuff = is.readAllBytes();
|
|
byte[] cBuff = is.readAllBytes();
|
|
|
|
+ java.net.URL resUrl = IPUtils.class.getClassLoader().getResource("ip/ip2region.xdb");
|
|
|
|
+ log.info("ip2region从classpath读取: url={}, bytes={}", resUrl, cBuff != null ? cBuff.length : null);
|
|
java.nio.file.Path tmp = java.nio.file.Files.createTempFile("ip2region", ".xdb");
|
|
java.nio.file.Path tmp = java.nio.file.Files.createTempFile("ip2region", ".xdb");
|
|
java.nio.file.Files.write(tmp, cBuff);
|
|
java.nio.file.Files.write(tmp, cBuff);
|
|
subtleSetDeleteOnExit(tmp);
|
|
subtleSetDeleteOnExit(tmp);
|
|
|
|
+ Long tmpSize = null; try { tmpSize = java.nio.file.Files.size(tmp); } catch (Exception ignore) {}
|
|
|
|
+ log.info("ip2region写入临时文件: path={}, size={} (bytes)", tmp, tmpSize);
|
|
searcher = Searcher.newWithFileOnly(tmp.toString());
|
|
searcher = Searcher.newWithFileOnly(tmp.toString());
|
|
log.info("ip2region初始化成功 (temp file: {})", tmp);
|
|
log.info("ip2region初始化成功 (temp file: {})", tmp);
|
|
}
|
|
}
|