public final class Reader extends Object implements Closeable
get method.| Modifier and Type | Class and Description |
|---|---|
static class | Reader.FileModeThe file mode to use when opening a MaxMind DB. |
| Constructor and Description |
|---|
Reader(File database)Constructs a Reader for the MaxMind DB format, with no caching. |
Reader(File database,
NodeCache cache)Constructs a Reader for the MaxMind DB format, with the specified backing
cache. |
Reader(File database,
Reader.FileMode fileMode)Constructs a Reader for the MaxMind DB format, with no caching. |
Reader(File database,
Reader.FileMode fileMode,
NodeCache cache)Constructs a Reader for the MaxMind DB format, with the specified backing
cache. |
Reader(InputStream source)Constructs a Reader with no caching, as if in mode
Reader.FileMode.MEMORY, without using a File instance. |
Reader(InputStream source,
NodeCache cache)Constructs a Reader with the specified backing cache, as if in mode
Reader.FileMode.MEMORY, without using a File instance. |
| Modifier and Type | Method and Description |
|---|---|
void | close()Closes the database. |
void | countryToIP(String country,
Writer out)I2P -
Write all IPv4 address ranges for the given country to out. |
Object | get(InetAddress ipAddress)Looks up the address in the MaxMind DB. |
Metadata | getMetadata()Returns the metadata for the MaxMind DB file. |
public Reader(File database) throws IOException
database - the MaxMind DB file to use.IOException - if there is an error opening or reading from the file.public Reader(File database, NodeCache cache) throws IOException
database - the MaxMind DB file to use.cache - backing cache instanceIOException - if there is an error opening or reading from the file.public Reader(File database, Reader.FileMode fileMode) throws IOException
database - the MaxMind DB file to use.fileMode - the mode to open the file with.IOException - if there is an error opening or reading from the file.public Reader(File database, Reader.FileMode fileMode, NodeCache cache) throws IOException
database - the MaxMind DB file to use.fileMode - the mode to open the file with.cache - backing cache instanceIOException - if there is an error opening or reading from the file.public Reader(InputStream source) throws IOException
Reader.FileMode.MEMORY, without using a File instance.source - the InputStream that contains the MaxMind DB file.IOException - if there is an error reading from the Stream.public Reader(InputStream source, NodeCache cache) throws IOException
Reader.FileMode.MEMORY, without using a File instance.source - the InputStream that contains the MaxMind DB file.cache - backing cache instanceIOException - if there is an error reading from the Stream.public void close()
throws IOExceptionCloses the database.
If you are using FileMode.MEMORY_MAPPED, this will
not unmap the underlying file due to a limitation in Java's
MappedByteBuffer. It will however set the reference to
the buffer to null, allowing the garbage collector to
collect it.
close in interface Closeableclose in interface AutoCloseableIOException - if an I/O error occurs.public void countryToIP(String country, Writer out) throws IOException
country - two-letter uppper-caseout - caller must closeIOException - on errorpublic Object get(InetAddress ipAddress) throws IOException
address in the MaxMind DB.ipAddress - the IP address to look up.IOException - if a file I/O error occurs.public Metadata getMetadata()