Skip to content

Commit b53b1ea

Browse files
Added function to read data from byte array instead of BIN file
1 parent b7c0a61 commit b53b1ea

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Below are the methods supported in this class.
3333
|---|---|
3434
|Open(String DBPath, boolean UseMMF)|Initialize the component and preload the BIN file.|
3535
|Open(String DBPath)|Initialize the component and preload the BIN file.|
36+
|Open(byte[] db)|Initialize the component with the byte array containing the BIN file data.|
3637
|IPQuery(String IPAddress)|Query IP address. This method returns results in com.ip2location.IPResult object.|
3738
|Close()|Destroys the mapped bytes.|
3839

@@ -80,6 +81,7 @@ Below are the status codes.
8081

8182
```java
8283
import com.ip2location.*;
84+
// import java.nio.file.*;
8385

8486
public class Main
8587
{
@@ -94,8 +96,15 @@ public class Main
9496
String binfile = "/usr/data/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY.BIN";
9597

9698
IP2Location loc = new IP2Location();
99+
100+
// this is to initialize with a BIN file
97101
loc.Open(binfile, true);
98102

103+
// this is to initialize with a byte array
104+
// Path binpath = Paths.get(binfile);
105+
// byte[] binFileBytes = Files.readAllBytes(binpath);
106+
// loc.Open(binFileBytes);
107+
99108
IPResult rec = loc.IPQuery(ip);
100109
if ("OK".equals(rec.getStatus()))
101110
{

com/ip2location/IP2Location.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* <p>
3737
*
3838
* @author IP2Location.com
39-
* @version 8.8.0
39+
* @version 8.9.0
4040
*/
4141
public class IP2Location {
4242
private static final Pattern pattern = Pattern.compile("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"); // IPv4

com/ip2location/IP2LocationWebService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* <p>
2929
*
3030
* @author IP2Location.com
31-
* @version 8.8.0
31+
* @version 8.9.0
3232
*/
3333
public class IP2LocationWebService {
3434
private static final Pattern pattern = Pattern.compile("^[\\dA-Z]{10}$");

com/ip2location/IPResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* <p>
1010
*
1111
* @author IP2Location.com
12-
* @version 8.8.0
12+
* @version 8.9.0
1313
*/
1414
public class IPResult {
1515
static final String NOT_SUPPORTED = "Not_Supported";
@@ -38,7 +38,7 @@ public class IPResult {
3838
String category;
3939
String status;
4040
boolean delay = false;
41-
String version = "Version 8.8.0";
41+
String version = "Version 8.9.0";
4242

4343
IPResult(String ipstring) {
4444
ip_address = ipstring;

com/ip2location/IPTools.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* <p>
3535
*
3636
* @author IP2Location.com
37-
* @version 8.8.0
37+
* @version 8.9.0
3838
*/
3939
public class IPTools {
4040
private static final BigInteger MAX_IPV4_RANGE = new BigInteger("4294967295");

0 commit comments

Comments
 (0)