diff --git a/src/getUrlResults.java b/src/getUrlResults.java index 2b01098..581f5e8 100644 --- a/src/getUrlResults.java +++ b/src/getUrlResults.java @@ -9,6 +9,7 @@ import java.util.List; public class getUrlResults { + private static int UnknownHostExceptionCount = 0; public static List getSearchResults(String searchText) { return getWordsList(downloadUrl(searchText), searchText); } @@ -30,7 +31,7 @@ } public static List downloadUrl(String searchWord) { - List lines = new ArrayList(); + List linesList = new ArrayList(); URL url; InputStream is = null; @@ -39,27 +40,25 @@ try { url = new URL("http://www.kryssakuten.se/Search.aspx?stype=ord-som-matchar-monster&sword=" + searchWord); - is = url.openStream(); // throws an IOException + is = url.openStream(); //Throws an IOException br = new BufferedReader(new InputStreamReader(is)); while ((line = br.readLine()) != null) { - lines.add(line); + linesList.add(line); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (UnknownHostException uhe) { - System.err.println("Error: No internet connection."); + System.err.println("Error: [" + ++UnknownHostExceptionCount + "] No internet connection."); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if (is != null) is.close(); - } catch (IOException ioe) { - // nothing to see here - } + } catch (IOException ioe) { } } - return lines; + return linesList; } } \ No newline at end of file