forked from I2P_Developers/i2p.i2p
* GeoIP: Read countries.txt in UTF-8
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
2011-05-22 zzz
|
||||||
|
* GeoIP: Read countries.txt in UTF-8
|
||||||
|
* Jetty: Fix build error that omitted local jetty patches from org.mortbay.jetty.jar;
|
||||||
|
affected 0.8.4 and 0.8.6 installers. Include jar in the updater for the next release.
|
||||||
|
|
||||||
2011-05-21 sponge
|
2011-05-21 sponge
|
||||||
* mbuild.sh document and fixes
|
* mbuild.sh document and fixes
|
||||||
* mbuild-all.sh add cpu types
|
* mbuild-all.sh add cpu types
|
||||||
|
@ -18,7 +18,7 @@ public class RouterVersion {
|
|||||||
/** deprecated */
|
/** deprecated */
|
||||||
public final static String ID = "Monotone";
|
public final static String ID = "Monotone";
|
||||||
public final static String VERSION = CoreVersion.VERSION;
|
public final static String VERSION = CoreVersion.VERSION;
|
||||||
public final static long BUILD = 2;
|
public final static long BUILD = 3;
|
||||||
|
|
||||||
/** for example "-test" */
|
/** for example "-test" */
|
||||||
public final static String EXTRA = "";
|
public final static String EXTRA = "";
|
||||||
|
@ -4,10 +4,12 @@ package net.i2p.router.transport;
|
|||||||
* Use at your own risk.
|
* Use at your own risk.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -37,8 +39,8 @@ import net.i2p.util.Log;
|
|||||||
* @author zzz
|
* @author zzz
|
||||||
*/
|
*/
|
||||||
class GeoIP {
|
class GeoIP {
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private RouterContext _context;
|
private final RouterContext _context;
|
||||||
private final Map<String, String> _codeToName;
|
private final Map<String, String> _codeToName;
|
||||||
private final Map<Long, String> _IPToCountry;
|
private final Map<Long, String> _IPToCountry;
|
||||||
private final Set<Long> _pendingSearch;
|
private final Set<Long> _pendingSearch;
|
||||||
@ -142,7 +144,7 @@ class GeoIP {
|
|||||||
private void readCountryFile() {
|
private void readCountryFile() {
|
||||||
File GeoFile = new File(_context.getBaseDir(), GEOIP_DIR_DEFAULT);
|
File GeoFile = new File(_context.getBaseDir(), GEOIP_DIR_DEFAULT);
|
||||||
GeoFile = new File(GeoFile, COUNTRY_FILE_DEFAULT);
|
GeoFile = new File(GeoFile, COUNTRY_FILE_DEFAULT);
|
||||||
if (GeoFile == null || (!GeoFile.exists())) {
|
if (!GeoFile.exists()) {
|
||||||
if (_log.shouldLog(Log.WARN))
|
if (_log.shouldLog(Log.WARN))
|
||||||
_log.warn("Country file not found: " + GeoFile.getAbsolutePath());
|
_log.warn("Country file not found: " + GeoFile.getAbsolutePath());
|
||||||
return;
|
return;
|
||||||
@ -150,19 +152,17 @@ class GeoIP {
|
|||||||
FileInputStream in = null;
|
FileInputStream in = null;
|
||||||
try {
|
try {
|
||||||
in = new FileInputStream(GeoFile);
|
in = new FileInputStream(GeoFile);
|
||||||
StringBuilder buf = new StringBuilder(128);
|
BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
|
||||||
while (DataHelper.readLine(in, buf)) {
|
String line = null;
|
||||||
|
while ( (line = br.readLine()) != null) {
|
||||||
try {
|
try {
|
||||||
if (buf.charAt(0) == '#') {
|
if (line.charAt(0) == '#') {
|
||||||
buf.setLength(0);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String[] s = buf.toString().split(",");
|
String[] s = line.split(",");
|
||||||
// todo convert name to mixed upper/lower case
|
|
||||||
_codeToName.put(s[0].toLowerCase(), s[1]);
|
_codeToName.put(s[0].toLowerCase(), s[1]);
|
||||||
} catch (IndexOutOfBoundsException ioobe) {
|
} catch (IndexOutOfBoundsException ioobe) {
|
||||||
}
|
}
|
||||||
buf.setLength(0);
|
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
if (_log.shouldLog(Log.ERROR))
|
if (_log.shouldLog(Log.ERROR))
|
||||||
|
Reference in New Issue
Block a user