This commit is contained in:
joewitt 2015-04-28 00:35:56 -04:00
parent 525ce7fb2d
commit e627482734
2 changed files with 20 additions and 34 deletions

View File

@ -191,12 +191,12 @@ public class GeoEnrichIP extends AbstractProcessor {
attrs.put(new StringBuilder(ipAttributeName).append(".geo.city").toString(), response.getCity().getName()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.city").toString(), response.getCity().getName());
final Double latitude = response.getLocation().getLatitude(); final Double latitude = response.getLocation().getLatitude();
if ( latitude != null ) { if (latitude != null) {
attrs.put(new StringBuilder(ipAttributeName).append(".geo.latitude").toString(), latitude.toString()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.latitude").toString(), latitude.toString());
} }
final Double longitude = response.getLocation().getLongitude(); final Double longitude = response.getLocation().getLongitude();
if ( longitude != null ) { if (longitude != null) {
attrs.put(new StringBuilder(ipAttributeName).append(".geo.longitude").toString(), longitude.toString()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.longitude").toString(), longitude.toString());
} }

View File

@ -43,17 +43,13 @@ import com.maxmind.geoip2.model.IspResponse;
/** /**
* <p> * <p>
* This class was copied from * This class was copied from https://raw.githubusercontent.com/maxmind/GeoIP2-java/master/src/main/java/com/maxmind/geoip2/DatabaseReader.java It is written by Maxmind and it is available under
* https://raw.githubusercontent.com/maxmind/GeoIP2-java/master/src/main/java/com/maxmind/geoip2/DatabaseReader.java * Apache Software License V2
* It is written by Maxmind and it is available under Apache Software License V2
* *
* The modification we're making to the code below is to stop using exceptions * The modification we're making to the code below is to stop using exceptions for mainline flow control. Specifically we don't want to throw an exception simply because an address was not found.
* for mainline flow control. Specifically we don't want to throw an exception
* simply because an address was not found.
* </p> * </p>
* *
* Instances of this class provide a reader for the GeoIP2 database format. IP * Instances of this class provide a reader for the GeoIP2 database format. IP addresses can be looked up using the <code>get</code> method.
* addresses can be looked up using the <code>get</code> method.
*/ */
public class DatabaseReader implements GeoIp2Provider, Closeable { public class DatabaseReader implements GeoIp2Provider, Closeable {
@ -84,12 +80,10 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
/** /**
* <p> * <p>
* Constructs a Builder for the DatabaseReader. The file passed to it must * Constructs a Builder for the DatabaseReader. The file passed to it must be a valid GeoIP2 database file.
* be a valid GeoIP2 database file.
* </p> * </p>
* <p> * <p>
* <code>Builder</code> creates instances of <code>DatabaseReader</code> * <code>Builder</code> creates instances of <code>DatabaseReader</code> from values set by the methods.
* from values set by the methods.
* </p> * </p>
* <p> * <p>
* Only the values set in the <code>Builder</code> constructor are required. * Only the values set in the <code>Builder</code> constructor are required.
@ -120,8 +114,7 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
} }
/** /**
* @param val List of locale codes to use in name property from most * @param val List of locale codes to use in name property from most preferred to least preferred.
* preferred to least preferred.
* @return Builder object * @return Builder object
*/ */
public Builder locales(List<String> val) { public Builder locales(List<String> val) {
@ -132,9 +125,7 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
/** /**
* @param val The file mode used to open the GeoIP2 database * @param val The file mode used to open the GeoIP2 database
* @return Builder object * @return Builder object
* @throws java.lang.IllegalArgumentException if you initialized the * @throws java.lang.IllegalArgumentException if you initialized the Builder with a URL, which uses {@link FileMode#MEMORY}, but you provided a different FileMode to this method.
* Builder with a URL, which uses {@link FileMode#MEMORY}, but you
* provided a different FileMode to this method.
*/ */
public Builder fileMode(FileMode val) { public Builder fileMode(FileMode val) {
if (this.stream != null && !FileMode.MEMORY.equals(val)) { if (this.stream != null && !FileMode.MEMORY.equals(val)) {
@ -146,8 +137,7 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
} }
/** /**
* @return an instance of <code>DatabaseReader</code> created from the * @return an instance of <code>DatabaseReader</code> created from the fields set on this builder.
* fields set on this builder.
* @throws IOException if there is an error reading the database * @throws IOException if there is an error reading the database
*/ */
public DatabaseReader build() throws IOException { public DatabaseReader build() throws IOException {
@ -157,10 +147,8 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
/** /**
* @param ipAddress IPv4 or IPv6 address to lookup. * @param ipAddress IPv4 or IPv6 address to lookup.
* @return An object of type T with the data for the IP address or null if no * @return An object of type T with the data for the IP address or null if no information could be found for the given IP address
* information could be found for the given IP address * @throws IOException if there is an error opening or reading from the file.
* @throws IOException if there is an error opening or reading from the
* file.
*/ */
private <T> T get(InetAddress ipAddress, Class<T> cls, boolean hasTraits, private <T> T get(InetAddress ipAddress, Class<T> cls, boolean hasTraits,
String type) throws IOException, AddressNotFoundException { String type) throws IOException, AddressNotFoundException {
@ -200,10 +188,8 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
* </p> * </p>
* <p> * <p>
* If you are using <code>FileMode.MEMORY_MAPPED</code>, this will * If you are using <code>FileMode.MEMORY_MAPPED</code>, this will
* <em>not</em> unmap the underlying file due to a limitation in Java's * <em>not</em> unmap the underlying file due to a limitation in Java's <code>MappedByteBuffer</code>. It will however set the reference to the buffer to <code>null</code>, allowing the garbage
* <code>MappedByteBuffer</code>. It will however set the reference to the * collector to collect it.
* buffer to <code>null</code>, allowing the garbage collector to collect
* it.
* </p> * </p>
* *
* @throws IOException if an I/O error occurs. * @throws IOException if an I/O error occurs.