[tor-bugs] #14859 [Onionoo]: Adapt Onionoo's parsing code for MaxMind's GeoLite2 City files to their new format
Tor Bug Tracker & Wiki
blackhole at torproject.org
Sat Feb 21 21:22:34 UTC 2015
#14859: Adapt Onionoo's parsing code for MaxMind's GeoLite2 City files to their new
format
-------------------------+-----------------
Reporter: karsten | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: Onionoo | Version:
Resolution: | Keywords:
Actual Points: | Parent ID:
Points: |
-------------------------+-----------------
Comment (by iwakeh):
Actually the implementations of the two InputStreamReader constructors
differ:
* the current code will internally use a decoder with
{{{CodingErrorAction.REPLACE}}}, i.e. drop erroneous input. (see
{{{java.io.InputStreamReader.java}}} and {{{sun.nio.cs.StreamDecoder}}})
* whereas, the constructor with the decoder parameter reports a
{{{java.nio.charset.MalformedInputException}}} (one subclass of
CharacterCodingException).
I couldn't make up an invalid utf-8 file. So, the code below demonstrates
the difference
using US-ASCII.
{{{
public class CharsetDecTest{
public static void main(String[] args)throws Exception{
String geo = "GeoLite2-City-Locations-en.csv";
try{
BufferedReader br1 =
new BufferedReader(new InputStreamReader(new
FileInputStream(new File(geo)), "US-ASCII"));
while(br1.readLine()!=null){}
}catch(Throwable t){
System.out.println("e1: " + t);
}
try{
BufferedReader br2 = new BufferedReader(
new InputStreamReader(new FileInputStream(new File(geo)),
StandardCharsets.US_ASCII.newDecoder()));
while(br2.readLine()!=null){}
}catch(Throwable t){
System.out.println("e2: " + t);
}
}
}
}}}
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/14859#comment:8>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
More information about the tor-bugs
mailing list