-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ankushs92/dev
Dev
- Loading branch information
Showing
27 changed files
with
571 additions
and
497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,62 @@ | ||
Java wrapper for the DB-IP dataset | ||
# Java DB-IP | ||
A simple to use Java library for the freely available DB-IP [IP address to city dataset](https://db-ip.com/db/download/city). | ||
**Requires Java 8** | ||
|
||
#Before you begin | ||
The entire dataset is loaded into a [TreeMap](https://docs.oracle.com/javase/8/docs/api/allclasses-noframe.html) . Make sure that you have about **3 GB of Heap space** available to load it. | ||
|
||
#Get | ||
|
||
With maven : | ||
|
||
```xml | ||
|
||
<dependency> | ||
<groupId>in.ankushs</groupId> | ||
<artifactId>Java-DB-IP</artifactId> | ||
<version>1.0</version> | ||
</dependency> | ||
``` | ||
|
||
Or gradle: | ||
|
||
```groovy | ||
compile('in.ankushs:Java-DB-IP:1.0') | ||
``` | ||
|
||
The Javadocs for the latest release can be found [here](http://www.javadoc.io/doc/in.ankushs/Java-DB-IP/1.0) | ||
|
||
|
||
#Instructions | ||
In order to get geographical information for an ip address, just pass the `dbip-city-latest.csv.gz` as a File object to `DbIpClient` as follows: | ||
|
||
```java | ||
File gzip = new File(PATH_TO_dbip-city-latest.csv.gz); | ||
DbIpClient client = new DbIpClient(gzip); | ||
``` | ||
|
||
Once the data is loaded from the file into memory , any subsequent invocation of the above code **would not** re-load the data . | ||
|
||
Next,just fetch the data for a ip ,like so : | ||
|
||
```java | ||
DbIpClient client = new DbIpClient(gzip); | ||
GeoEntity geoEntity = client.lookup("31.45.127.255"); | ||
String city = geoEntity.getCity(); | ||
String country = geoEntity.getCountry(); | ||
String province = geoEntity.getProvince(); | ||
|
||
System.out.println("city : " + city); | ||
System.out.println("province : " + province); | ||
System.out.println("country : " + country); | ||
``` | ||
|
||
This prints : | ||
``` | ||
city : Oslo | ||
province : Oslo | ||
country : Norway | ||
``` | ||
That's pretty much it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
apply plugin: 'groovy' | ||
apply plugin: 'eclipse' | ||
apply plugin : 'idea' | ||
|
||
apply plugin: 'maven' | ||
apply plugin: 'signing' | ||
|
||
|
||
sourceCompatibility = 1.8 | ||
group ="in.ankushs" | ||
archivesBaseName = "dbip" | ||
version = '1.0' | ||
|
||
jar { | ||
baseName = "Java DbIp" | ||
baseName = "Java-DB-IP" | ||
manifest { | ||
attributes 'Implementation-Title': 'Gradle Quickstart', | ||
'Implementation-Version': version | ||
|
@@ -26,13 +31,13 @@ dependencies { | |
testCompile('org.codehaus.groovy:groovy-all:2.4.5') | ||
} | ||
|
||
sourceSets { | ||
main { | ||
java { srcDirs = ["src/main/java"] } // no source dirs for the java compiler | ||
groovy { srcDirs = ["src/test/groovy"] } // compile everything in src/ with groovy | ||
} | ||
} | ||
|
||
//sourceSets { | ||
// main { | ||
// java { srcDirs = ["src/main/java"] } // no source dirs for the java compiler | ||
// groovy { srcDirs = ["src/test/groovy"] } // compile everything in src/ with groovy | ||
// } | ||
// } | ||
// | ||
test { | ||
systemProperties 'property': 'value' | ||
} | ||
|
@@ -44,11 +49,73 @@ eclipse { | |
} | ||
} | ||
|
||
|
||
task javadocJar(type: Jar) { | ||
classifier = 'javadoc' | ||
from javadoc | ||
} | ||
|
||
task sourcesJar(type: Jar) { | ||
classifier = 'sources' | ||
from sourceSets.main.allSource | ||
} | ||
|
||
artifacts { | ||
archives javadocJar, sourcesJar | ||
} | ||
|
||
signing { | ||
sign configurations.archives | ||
} | ||
|
||
|
||
uploadArchives { | ||
repositories { | ||
flatDir { | ||
dirs 'repos' | ||
} | ||
mavenDeployer{ | ||
beforeDeployment{MavenDeployment deployment-> | ||
signing.signPom(deployment) | ||
} | ||
|
||
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2") { | ||
authentication(userName: ossrhUsername, password: ossrhPassword) | ||
} | ||
|
||
pom{ | ||
project{ | ||
name 'Java DbIP' | ||
description 'A Java library for the DB-IP IP address to city dataset ' | ||
packaging 'jar' | ||
url 'https://github.com/ankushs92/Java-DB-IP' | ||
inceptionYear '2016' | ||
|
||
scm { | ||
connection 'scm:git:[email protected]:ankushs92/Java-DB-IP.git' | ||
developerConnection 'scm:git:[email protected]:ankushs92/Java-DB-IP.git' | ||
url '[email protected]:ankushs92/Java-DB-IP.git' | ||
} | ||
|
||
licenses { | ||
license { | ||
name 'The MIT License' | ||
url 'https://github.com/ankushs92/Java-DB-IP/blob/master/LICENSE.md' | ||
} | ||
} | ||
developers { | ||
developer { | ||
name 'Ankush Sharma' | ||
email '[email protected]' | ||
} | ||
} | ||
issueManagement{ | ||
system 'Github' | ||
url 'https://github.com/ankushs92/Java-DB-IP/issues' | ||
|
||
} | ||
} | ||
} | ||
flatDir { | ||
dirs 'repos' | ||
} | ||
} | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.