public static void main(String[] args) throws Exception {
URL target = new URL("http://hibari.2ch.net/tech/dat/1272608727.dat");
InputStream in = null;
int unkoCnt = 0;
try {
HttpURLConnection ucon = (HttpURLConnection) target.openConnection();
ucon.setRequestProperty("User-Agent", "Monazilla/1.00 (UnkoCounter/1.0)");
ucon.setRequestProperty("Accept-Encoding", "gzip, deflate");
ucon.setRequestProperty("Accept", "*/*");
in = ucon.getInputStream();
String enc = ucon.getContentEncoding();
if (enc != null && enc.equals("gzip") && (in instanceof GZIPInputStream) == false) in = new GZIPInputStream(in);
if ( enc != null && enc.equals("deflate") && (in instanceof DeflaterInputStream) == false) in = new DeflaterInputStream(in);
in = new BufferedInputStream(in, 65536);
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "Windows-31J"), 8192);
String line = null;
while ( (line = reader.readLine()) != null ) {
String[] ary = line.split("<>");
if ( ary[0].indexOf("あぼーん") != -1 || ary.length < 3 )
continue;
String honbun = ary[3];
if ( countKuso(honbun) != -1 )
unkoCnt++;
}
}finally {
if ( in != null ) in.close();
}
System.out.printf("%d個のウンコを発見。\n", unkoCnt);
}
<<続く>>