|
1 | | -<!doctype html><html lang=en><head><meta name=generator content="Hugo 0.161.1"><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>GeoIP Java API</title><link rel=stylesheet href=/GeoIP2-java/css/main.281d4a083c59f78015bdb60748317bf7d39ad62d8c9c6cead28bce0cc0794b5e.css integrity="sha256-KB1KCDxZ94AVvbYHSDF799Oa1i2MnGzq0ovODMB5S14=" crossorigin=anonymous></head><body><nav class=page-nav><a href=/GeoIP2-java/ class=active aria-current=page>Overview</a> |
| 1 | +<!doctype html><html lang=en><head><meta name=generator content="Hugo 0.163.3"><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>GeoIP Java API</title><link rel=stylesheet href=/GeoIP2-java/css/main.281d4a083c59f78015bdb60748317bf7d39ad62d8c9c6cead28bce0cc0794b5e.css integrity="sha256-KB1KCDxZ94AVvbYHSDF799Oa1i2MnGzq0ovODMB5S14=" crossorigin=anonymous></head><body><nav class=page-nav><a href=/GeoIP2-java/ class=active aria-current=page>Overview</a> |
2 | 2 | <a href=/GeoIP2-java/doc/latest/>API documentation</a></nav><main><h1 id=geoip-java-api>GeoIP Java API<a class=heading-anchor href=#geoip-java-api aria-label="Link to GeoIP Java API">#</a></h1><h2 id=description>Description<a class=heading-anchor href=#description aria-label="Link to Description">#</a></h2><p>This distribution provides an API for the GeoIP and GeoLite <a href="https://dev.maxmind.com/geoip/docs/web-services/?lang=en">web |
3 | 3 | services</a> and |
4 | 4 | <a href="https://dev.maxmind.com/geoip/docs/databases/?lang=en">databases</a>.</p><h2 id=installation>Installation<a class=heading-anchor href=#installation aria-label="Link to Installation">#</a></h2><h3 id=maven>Maven<a class=heading-anchor href=#maven aria-label="Link to Maven">#</a></h3><p>We recommend installing this package with <a href=https://maven.apache.org/>Maven</a>. |
|
182 | 182 | Maven, you must |
183 | 183 | <a href=https://maven.apache.org/plugins/maven-resources-plugin/examples/binaries-filtering.html>disable binary file filtering</a>. |
184 | 184 | Failure to do so will result in <code>InvalidDatabaseException</code> exceptions being |
185 | | -thrown when querying the database.</p><h2 id=database-example>Database Example<a class=heading-anchor href=#database-example aria-label="Link to Database Example">#</a></h2><h3 id=city>City<a class=heading-anchor href=#city aria-label="Link to City">#</a></h3><div class=highlight><pre tabindex=0 style=background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none><code class=language-java data-lang=java><span style=display:flex><span><span style=color:#57606a>// A File object pointing to your GeoIP or GeoLite database</span><span style=color:#fff> |
| 185 | +thrown when querying the database.</p><h3 id=file-lock-on-windows>File Lock on Windows<a class=heading-anchor href=#file-lock-on-windows aria-label="Link to File Lock on Windows">#</a></h3><p>By default, the <code>DatabaseReader</code> uses the <code>MEMORY_MAPPED</code> file mode, which |
| 186 | +memory maps the database file. On Windows, a live memory mapping may prevent |
| 187 | +the file from being renamed, replaced, or deleted. This is not a Java |
| 188 | +<code>FileLock</code>, but it can have similar effects when updating a database file in |
| 189 | +place.</p><p>Closing the <code>DatabaseReader</code> releases its reference to the mapped buffer, but |
| 190 | +Java does not provide a supported way to unmap the underlying |
| 191 | +<code>MappedByteBuffer</code> immediately. The mapping remains valid until the buffer |
| 192 | +becomes unreachable and is garbage collected.</p><p>To avoid this behavior, configure the <code>Builder</code> with <code>FileMode.MEMORY</code>. If you |
| 193 | +must use <code>MEMORY_MAPPED</code>, close and dereference the <code>DatabaseReader</code> before |
| 194 | +replacing the file. You may call <code>System.gc()</code> to encourage earlier cleanup, |
| 195 | +but garbage collection is not guaranteed to run immediately.</p><h2 id=database-example>Database Example<a class=heading-anchor href=#database-example aria-label="Link to Database Example">#</a></h2><h3 id=city>City<a class=heading-anchor href=#city aria-label="Link to City">#</a></h3><div class=highlight><pre tabindex=0 style=background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none><code class=language-java data-lang=java><span style=display:flex><span><span style=color:#57606a>// A File object pointing to your GeoIP or GeoLite database</span><span style=color:#fff> |
186 | 196 | </span></span></span><span style=display:flex><span>File<span style=color:#fff> </span>database<span style=color:#fff> </span><span style=color:#0550ae>=</span><span style=color:#fff> </span><span style=color:#cf222e>new</span><span style=color:#fff> </span>File<span style=color:#1f2328>(</span><span style=color:#0a3069>"/path/to/GeoIP2-City.mmdb"</span><span style=color:#1f2328>);</span><span style=color:#fff> |
187 | 197 | </span></span></span><span style=display:flex><span><span style=color:#fff> |
188 | 198 | </span></span></span><span style=display:flex><span><span style=color:#57606a>// This creates the DatabaseReader object. To improve performance, reuse</span><span style=color:#fff> |
|
0 commit comments