From 77bfec0122553f81314296af302e6b429b082592 Mon Sep 17 00:00:00 2001 From: Karsten Loesing Date: Tue, 19 Jan 2010 19:40:56 +0100 Subject: [PATCH] Don't fail if extra-info descriptors are missing. --- src/ExtraInfoDownloader.java | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/ExtraInfoDownloader.java b/src/ExtraInfoDownloader.java index 6ab7143..d8f6719 100644 --- a/src/ExtraInfoDownloader.java +++ b/src/ExtraInfoDownloader.java @@ -10,20 +10,28 @@ public class ExtraInfoDownloader { + authority + "... "); Stack extraInfos = new Stack(); for (String fingerprint : directories.keySet()) { - BufferedInputStream in = new BufferedInputStream(new URL( - "http://" + authority + "/tor/extra/fp/" + fingerprint). - openStream()); - StringBuilder sb = new StringBuilder(); - int len; - byte[] data = new byte[1024]; - while ((len = in.read(data, 0, 1024)) >= 0) { - sb.append(new String(data, 0, len)); - } - in.close(); - String extraInfo = sb.toString(); - if (extraInfo.length() > 0) { - BufferedReader br = new BufferedReader(new StringReader(extraInfo)); - rdp.parse(br); + URL u = new URL("http://" + authority + "/tor/extra/fp/" + + fingerprint); + HttpURLConnection huc = (HttpURLConnection) u.openConnection(); + huc.setRequestMethod("GET"); + huc.connect(); + int response = huc.getResponseCode(); + if (response == 200) { + BufferedInputStream in = new BufferedInputStream( + huc.getInputStream()); + StringBuilder sb = new StringBuilder(); + int len; + byte[] data = new byte[1024]; + while ((len = in.read(data, 0, 1024)) >= 0) { + sb.append(new String(data, 0, len)); + } + in.close(); + String extraInfo = sb.toString(); + if (extraInfo.length() > 0) { + BufferedReader br = new BufferedReader( + new StringReader(extraInfo)); + rdp.parse(br); + } } } System.out.println("done");