From 606300a042ee587aed9f71402c1b03964dfcf258 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sun, 22 May 2011 18:36:08 +0000 Subject: [PATCH] * GeoIP: Read countries.txt in UTF-8 --- history.txt | 5 +++++ .../src/net/i2p/router/RouterVersion.java | 2 +- .../src/net/i2p/router/transport/GeoIP.java | 20 +++++++++---------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/history.txt b/history.txt index 9d26d6dac..aafbc61d0 100644 --- a/history.txt +++ b/history.txt @@ -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 * mbuild.sh document and fixes * mbuild-all.sh add cpu types diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 282c18b42..0725033fa 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 2; + public final static long BUILD = 3; /** for example "-test" */ public final static String EXTRA = ""; diff --git a/router/java/src/net/i2p/router/transport/GeoIP.java b/router/java/src/net/i2p/router/transport/GeoIP.java index 1593487cf..a701a24af 100644 --- a/router/java/src/net/i2p/router/transport/GeoIP.java +++ b/router/java/src/net/i2p/router/transport/GeoIP.java @@ -4,10 +4,12 @@ package net.i2p.router.transport; * Use at your own risk. */ +import java.io.BufferedReader; import java.io.IOException; import java.io.File; import java.io.FileInputStream; import java.net.InetAddress; +import java.io.InputStreamReader; import java.net.UnknownHostException; import java.util.Arrays; import java.util.Map; @@ -37,8 +39,8 @@ import net.i2p.util.Log; * @author zzz */ class GeoIP { - private Log _log; - private RouterContext _context; + private final Log _log; + private final RouterContext _context; private final Map<String, String> _codeToName; private final Map<Long, String> _IPToCountry; private final Set<Long> _pendingSearch; @@ -142,7 +144,7 @@ class GeoIP { private void readCountryFile() { File GeoFile = new File(_context.getBaseDir(), GEOIP_DIR_DEFAULT); GeoFile = new File(GeoFile, COUNTRY_FILE_DEFAULT); - if (GeoFile == null || (!GeoFile.exists())) { + if (!GeoFile.exists()) { if (_log.shouldLog(Log.WARN)) _log.warn("Country file not found: " + GeoFile.getAbsolutePath()); return; @@ -150,19 +152,17 @@ class GeoIP { FileInputStream in = null; try { in = new FileInputStream(GeoFile); - StringBuilder buf = new StringBuilder(128); - while (DataHelper.readLine(in, buf)) { + BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); + String line = null; + while ( (line = br.readLine()) != null) { try { - if (buf.charAt(0) == '#') { - buf.setLength(0); + if (line.charAt(0) == '#') { continue; } - String[] s = buf.toString().split(","); - // todo convert name to mixed upper/lower case + String[] s = line.split(","); _codeToName.put(s[0].toLowerCase(), s[1]); } catch (IndexOutOfBoundsException ioobe) { } - buf.setLength(0); } } catch (IOException ioe) { if (_log.shouldLog(Log.ERROR)) -- GitLab