

This is free software, licensed under the Apache License, Version 2.0.
#MAXMIND GEOIP2 SOFTWARE#
This software is Copyright (c) 2014-2020 by MaxMind, Inc. The MaxMind DB Reader API uses Semantic Versioning. Patches and pull requests are encouraged. If you are having an issue with a MaxMind database or service that is not
#MAXMIND GEOIP2 CODE#
Please report all issues with this code using the GitHub issue The MaxMind DB format is an open format for quickly mapping IP addresses to If you are packaging the database file as a resource in a JAR file usingįailure to do so will result in InvalidDatabaseException exceptions being You may also call System.gc() after dereferencing theĭatabaseReader object to encourage the JVM to garbage collect sooner. To work around this problem, use the MEMORY mode or try upgrading your JVM Older JVM versions may also not release the lock on exit. Will only be released when the object and the MappedByteBuffer it uses are Java, this lock will not be released when the DatabaseReader is closed it Due to the implementation of memory mapping in On Windows, this may create an exclusive lock on the file that prevents itįrom being renamed or deleted. Common Problems File Lock on Windowsīy default, this API uses the MEMORY_MAP mode, which memory maps the file. In suchĪpplications, we suggest creating one Reader object and sharing that among This API fully supports use in multi-threaded applications. Returned from the cache on subsequent lookups. If you mutate the objects, the mutated objects will be Please note that the cache will hold references to the objects createdĭuring the lookup. The GeoIP2 City database is a more accurate version of our free GeoLite2 City database. Reader reader = new Reader ( database, new CHMCache ()) To access our most accurate IP geolocation data, use GeoIP2 Precision: City or Insights, which accurately geolocate 4 more IPs to cities and 9 more IPs to postal codes in the United States than the GeoIP2 City database. Using this cache, lookup performance is significantly improved at the cost of A simple implementation is provided by .CHMCache. The database API supports pluggable caching (by default, no caching is Import .MaxMindDbConstructor import .MaxMindDbParameter import .Reader import .Record import java.io.File import java.io.IOException import public class Lookup Caching The creation of this object is relatively expensive as it must We recommend reusing the Reader object rather than creating a new one forĮach lookup. This method will create an instance of the class and Method on Reader, along with the class of the object you want toĭeserialize into. To look up an IP address, pass the address as an InetAddress to the get This often provides performance comparable to loading the file into The default mode is MEMORY_MAP, which maps the file to virtual May pass a second parameter with a FileMode with a value of MEMORY_MAP or The reader object takes a File representing your MaxMind DB. To use the API, you must first create a Reader object. Note: For accessing MaxMind GeoIP2 databases, we generally recommend using
