mirror of
https://github.com/lionsoul2014/ip2region.git
synced 2025-12-08 19:25:22 +00:00
rename searchByStr to search and default the region encode to utf-8
This commit is contained in:
parent
4a2fae35e6
commit
cbf79d4682
@ -89,7 +89,7 @@ public class SearchTest {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
double sTime = System.nanoTime();
|
double sTime = System.nanoTime();
|
||||||
String region = searcher.searchByStr(line);
|
String region = searcher.search(line);
|
||||||
long cost = TimeUnit.NANOSECONDS.toMicros((long) (System.nanoTime() - sTime));
|
long cost = TimeUnit.NANOSECONDS.toMicros((long) (System.nanoTime() - sTime));
|
||||||
System.out.printf("{region: %s, ioCount: %d, took: %d μs}\n", region, searcher.getIOCount(), cost);
|
System.out.printf("{region: %s, ioCount: %d, took: %d μs}\n", region, searcher.getIOCount(), cost);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@ -71,7 +71,7 @@ public class Searcher {
|
|||||||
return ioCount;
|
return ioCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String searchByStr(String ipStr) throws Exception {
|
public String search(String ipStr) throws Exception {
|
||||||
long ip = checkIP(ipStr);
|
long ip = checkIP(ipStr);
|
||||||
return search(ip);
|
return search(ip);
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ public class Searcher {
|
|||||||
// load and return the region data
|
// load and return the region data
|
||||||
final byte[] regionBuff = new byte[dataLen];
|
final byte[] regionBuff = new byte[dataLen];
|
||||||
read(dataPtr, regionBuff);
|
read(dataPtr, regionBuff);
|
||||||
return new String(regionBuff);
|
return new String(regionBuff, "utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void read(int offset, byte[] buffer) throws IOException {
|
protected void read(int offset, byte[] buffer) throws IOException {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user