public class IP2Location extends Object
This class provides direct access to IP2Location binary database files,
supporting both standard file I/O and memory-mapped file access for optimal
performance. It is used internally by IP2LocationService.
| Mode | Heap Memory | Performance | Use Case |
|---|---|---|---|
| Memory-mapped | Minimal (~1 KB) | Faster random access | Production servers with RAM |
| Standard | Varies with caching | Predictable | Containers, limited memory |
This class is thread-safe. In memory-mapped mode, reads use absolute
buffer access and require no locking, allowing full concurrency. In standard
I/O mode, reads are synchronized on an internal lock since
RandomAccessFile is not thread-safe.
Supports all 26 IP2Location database types (DB1-DB26), including both LITE and commercial databases. Field position tables are copied verbatim from the upstream reference implementation (v8.13.0) for accuracy.
6to4 (2002::/16) and Teredo (2001:0000::/32) addresses
are automatically remapped to their embedded IPv4 address for lookup in
the IPv4 table, matching the upstream reference behavior.
IP2Location loc = new IP2Location();
try {
loc.Open("/path/to/IP2LOCATION-LITE-DB11.BIN", true); // memory-mapped
IPResult result = loc.IPQuery("8.8.8.8");
if ("OK".equals(result.getStatus())) {
System.out.println("Country: " + result.getCountryShort());
System.out.println("City: " + result.getCity());
}
} finally {
loc.Close();
}
IP2LocationService,
IPResult| Constructor and Description |
|---|
IP2Location() |
| Modifier and Type | Method and Description |
|---|---|
void |
Close() |
LocalDate |
getDatabaseDate() |
String |
getDatabasePath() |
int |
getDatabaseType() |
String |
getDatabaseVersion() |
boolean |
hasIPv6Support() |
IPResult |
IPQuery(String ipAddress) |
boolean |
isLoaded() |
void |
Open(String databasePath) |
void |
Open(String databasePath,
boolean useMemoryMappedFile) |
public void Open(String databasePath, boolean useMemoryMappedFile) throws IOException
IOExceptionpublic void Open(String databasePath) throws IOException
IOExceptionpublic void Close()
public int getDatabaseType()
public String getDatabaseVersion()
public LocalDate getDatabaseDate()
public boolean isLoaded()
public boolean hasIPv6Support()
public String getDatabasePath()
Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© 2026 Mindus SARL. All rights reserved.