use of com.maxmind.geoip2.DatabaseReader in project divolte-collector by divolte.
the class DatabaseLookupService method loadExternalDatabase.
private static DatabaseReader loadExternalDatabase(final Path location) throws IOException {
/*
* We have 2 strategies here.
* 1) If compressed, we load via a stream (which means into memory).
* 2) If it's not compressed, we pass a File in directly which allows DatabaseReader
* to mmap(2) the file.
*/
final DatabaseReader reader;
if ("gz".equals(com.google.common.io.Files.getFileExtension(location.toString()))) {
try (final InputStream rawStream = Files.newInputStream(location);
final InputStream bufferedStream = new BufferedInputStream(rawStream);
final InputStream dbStream = new GZIPInputStream(bufferedStream)) {
logger.debug("Loading compressed GeoIP database: {}", location);
reader = new DatabaseReader.Builder(dbStream).build();
}
} else {
logger.debug("Loading GeoIP database: {}", location);
reader = new DatabaseReader.Builder(location.toFile()).build();
}
logger.info("Loaded GeoIP database: {}", location);
return reader;
}
use of com.maxmind.geoip2.DatabaseReader in project bender by Nextdoor.
the class GeoIpOperationTest method setup.
public GeoIpOperation setup(List<GeoProperty> geoProperties, boolean required) throws IOException {
InputStream is = this.getClass().getResourceAsStream("my-ip-data.mmdb");
DatabaseReader dr = new DatabaseReader.Builder(is).build();
return new GeoIpOperation("ip_address", "geo_ip", dr, geoProperties, required);
}
use of com.maxmind.geoip2.DatabaseReader in project Nucleus by NucleusPowered.
the class GeoIpDatabaseHandler method onRun.
private void onRun(LoadType type) {
try {
isLoading = true;
// Check in case we need it.
downloadUpdate(type == LoadType.DOWNLOAD);
if (databaseReader != null) {
databaseReader.close();
}
InputStream inputStream = new FileInputStream(countries.toFile());
databaseReader = new DatabaseReader.Builder(inputStream).withCache(new CHMCache()).fileMode(Reader.FileMode.MEMORY).build();
} catch (Exception e) {
e.printStackTrace();
} finally {
isLoading = false;
}
}
use of com.maxmind.geoip2.DatabaseReader in project nutch by apache.
the class GeoIPDocumentCreator method createDocFromDomainDb.
public static NutchDocument createDocFromDomainDb(String serverIp, NutchDocument doc, DatabaseReader reader) throws UnknownHostException, IOException, GeoIp2Exception {
DomainResponse response = reader.domain(InetAddress.getByName(serverIp));
addIfNotNull(doc, "ip", serverIp);
addIfNotNull(doc, "domain", response.getDomain());
return doc;
}
use of com.maxmind.geoip2.DatabaseReader in project nutch by apache.
the class GeoIPDocumentCreator method createDocFromConnectionDb.
public static NutchDocument createDocFromConnectionDb(String serverIp, NutchDocument doc, DatabaseReader reader) throws UnknownHostException, IOException, GeoIp2Exception {
ConnectionTypeResponse response = reader.connectionType(InetAddress.getByName(serverIp));
addIfNotNull(doc, "ip", serverIp);
addIfNotNull(doc, "connType", response.getConnectionType().toString());
return doc;
}
Aggregations