forked from lionsoul2014/ip2region
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the java implementation for ip2region.db maker
- Loading branch information
1 parent
9d23bc5
commit abf2292
Showing
13 changed files
with
1,642 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project name="ip2region" default="usage" basedir="."> | ||
<!--Initialize--> | ||
<target name="init"> | ||
<echo message="------------------------------------------------------------"/> | ||
<echo message="----------BUILDING JCSEG PACKAGE----------------------------"/> | ||
<echo message=""/> | ||
<property name="bottom" value="ip2region 2015-2019"/> | ||
<property name="jars" value="${basedir}"/> | ||
<property name="sources" value="${basedir}/src"/> | ||
<property name="classes" value="${basedir}/classes"/> | ||
<property name="version" value="1.2.2"/> | ||
<property name="api" value="${basedir}/doc"/> | ||
<mkdir dir="${classes}"/> | ||
<mkdir dir="${api}"/> | ||
</target> | ||
|
||
<path id="classpath"> | ||
<fileset dir="${lib.dir}" includes="**/*.jar"/> | ||
</path> | ||
|
||
<!--Build--> | ||
<target name="build" depends="init"> | ||
<echo message="-------------Compiling Application--------------"/> | ||
<javac srcdir="${sources}" destdir="${classes}"></javac> | ||
</target> | ||
|
||
<!--Archive--> | ||
<target name="dist" depends="build"> | ||
<jar jarfile="${jars}/ip2region-${version}.jar" basedir="${classes}"> | ||
<!--class fileter--> | ||
<include name="**/*"/> | ||
<!--manifest information setting--> | ||
<manifest> | ||
<attribute name="Main-Class" value="org.lionsoul.ip2region.test.TestSearcher"/> | ||
<attribute name="Class-Path" value=""/> | ||
</manifest> | ||
</jar> | ||
<jar jarfile="${jars}/dbMaker-${version}.jar" basedir="${classes}" includes="org/lionsoul/ip2region/*"> | ||
<!--manifest information setting--> | ||
<manifest> | ||
<attribute name="Main-Class" value="org.lionsoul.ip2region.DbMaker"/> | ||
<attribute name="Class-Path" value=""/> | ||
</manifest> | ||
</jar> | ||
</target> | ||
|
||
<!--Java document--> | ||
<target name="all" depends="dist"> | ||
<echo message="------------Making Java Document------------------"/> | ||
<javadoc packagenames="org.*" | ||
sourcepath="${sources}" | ||
destdir="${api}" | ||
bottom="${bottom}" | ||
charset="UTF-8" | ||
author="false"> | ||
<classpath> | ||
<pathelement location="${classes}"/> | ||
</classpath> | ||
</javadoc> | ||
<jar jarfile="${jars}/ip2region-${version}-javadoc.jar" basedir="${api}" includes="**/*"></jar> | ||
|
||
<!--do the data clean up--> | ||
<delete dir="${classes}"/> | ||
<delete dir="${api}"/> | ||
</target> | ||
|
||
<target name="usage"> | ||
<echo message="*** ip2region ANT Build Script ***"/> | ||
<echo message="Usage: "/> | ||
<echo message=" ant [target]"/> | ||
<echo message=""/> | ||
<echo message=" target : "/> | ||
<echo message=" build : Build Application"/> | ||
<echo message=" dist : Build Application + Archive (JAR)"/> | ||
<echo message=" all : Build Application + Archive + JavaDoc"/> | ||
</target> | ||
|
||
</project> |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.lionsoul.ip2region; | ||
|
||
/** | ||
* data block class | ||
* | ||
* @author chenxin<[email protected]> | ||
*/ | ||
public class DataBlock | ||
{ | ||
/** | ||
* city id | ||
*/ | ||
private int city_id; | ||
|
||
/** | ||
* region address | ||
*/ | ||
private String region; | ||
|
||
/** | ||
* region ptr in the db file | ||
*/ | ||
private int dataPtr; | ||
|
||
/** | ||
* construct method | ||
* | ||
* @param city_id | ||
* @param region region string | ||
* @param dataPtr data ptr | ||
*/ | ||
public DataBlock( int city_id, String region, int dataPtr ) | ||
{ | ||
this.city_id = city_id; | ||
this.region = region; | ||
this.dataPtr = dataPtr; | ||
} | ||
|
||
public DataBlock(int city_id, String region) | ||
{ | ||
this(city_id, region, 0); | ||
} | ||
|
||
public int getCityId() | ||
{ | ||
return city_id; | ||
} | ||
|
||
public DataBlock setCityId(int city_id) | ||
{ | ||
this.city_id = city_id; | ||
return this; | ||
} | ||
|
||
public String getRegion() | ||
{ | ||
return region; | ||
} | ||
|
||
public DataBlock setRegion(String region) | ||
{ | ||
this.region = region; | ||
return this; | ||
} | ||
|
||
public int getDataPtr() | ||
{ | ||
return dataPtr; | ||
} | ||
|
||
public DataBlock setDataPtr(int dataPtr) | ||
{ | ||
this.dataPtr = dataPtr; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
sb.append(city_id).append('|').append(region).append('|').append(dataPtr); | ||
return sb.toString(); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.lionsoul.ip2region; | ||
|
||
/** | ||
* database configuration class | ||
* | ||
* @author chenxin<[email protected]> | ||
*/ | ||
public class DbConfig | ||
{ | ||
/** | ||
* total header data block size | ||
*/ | ||
private int totalHeaderSize; | ||
|
||
/** | ||
* max index data block size | ||
* u should always choice the fastest read block size | ||
*/ | ||
private int indexBlockSize; | ||
|
||
/** | ||
* construct method | ||
* | ||
* @param totalHeaderSize | ||
* @throws DbMakerConfigException | ||
*/ | ||
public DbConfig( int totalHeaderSize ) throws DbMakerConfigException | ||
{ | ||
if ( (totalHeaderSize % 8) != 0 ) { | ||
throw new DbMakerConfigException("totalHeaderSize must be times of 8"); | ||
} | ||
|
||
this.totalHeaderSize = totalHeaderSize; | ||
this.indexBlockSize = 8192; //4 * 2048 | ||
} | ||
|
||
public DbConfig() throws DbMakerConfigException | ||
{ | ||
this(8 * 2048); | ||
} | ||
|
||
public int getTotalHeaderSize() | ||
{ | ||
return totalHeaderSize; | ||
} | ||
|
||
public DbConfig setTotalHeaderSize(int totalHeaderSize) | ||
{ | ||
this.totalHeaderSize = totalHeaderSize; | ||
return this; | ||
} | ||
|
||
public int getIndexBlockSize() | ||
{ | ||
return indexBlockSize; | ||
} | ||
|
||
public DbConfig setIndexBlockSize(int dataBlockSize) | ||
{ | ||
this.indexBlockSize = dataBlockSize; | ||
return this; | ||
} | ||
} |
Oops, something went wrong.