X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=util%2Forg%2Fcacert%2Fgigi%2Futil%2FHighFinancialValueFetcher.java;h=338b8ae2e324c68285c7c81dcc74dafeba221295;hp=c05c7ca608973dff13ffbf5e55b9183b2b2fbb7b;hb=41475d570b891d2af3a541298fd89a4c0dfb4ab5;hpb=258fed97058e563788f5b598097daa880921e500 diff --git a/util/org/cacert/gigi/util/HighFinancialValueFetcher.java b/util/org/cacert/gigi/util/HighFinancialValueFetcher.java index c05c7ca6..338b8ae2 100644 --- a/util/org/cacert/gigi/util/HighFinancialValueFetcher.java +++ b/util/org/cacert/gigi/util/HighFinancialValueFetcher.java @@ -16,26 +16,25 @@ public class HighFinancialValueFetcher { if (args.length > 1) { max = Integer.parseInt(args[1]); } - PrintWriter fos = new PrintWriter(new File(args[0]), "UTF-8"); - ZipInputStream zis = new ZipInputStream(new URL("https://s3.amazonaws.com/alexa-static/top-1m.csv.zip").openStream()); - ZipEntry ze; - outer: - while ((ze = zis.getNextEntry()) != null) { - System.out.println(ze.getName()); - BufferedReader br = new BufferedReader(new InputStreamReader(zis, "UTF-8")); - String line; - while ((line = br.readLine()) != null) { - String[] parts = line.split(","); - int i = Integer.parseInt(parts[0]); - if (i > max) { - zis.close(); - break outer; + try (PrintWriter fos = new PrintWriter(new File(args[0]), "UTF-8"); ZipInputStream zis = new ZipInputStream(new URL("https://s3.amazonaws.com/alexa-static/top-1m.csv.zip").openStream())) { + ZipEntry ze; + outer: + while ((ze = zis.getNextEntry()) != null) { + System.out.println(ze.getName()); + BufferedReader br = new BufferedReader(new InputStreamReader(zis, "UTF-8")); + String line; + while ((line = br.readLine()) != null) { + String[] parts = line.split(","); + int i = Integer.parseInt(parts[0]); + if (i > max) { + zis.close(); + break outer; + } + fos.println(parts[1]); + System.out.println(line); } - fos.println(parts[1]); - System.out.println(line); } } - fos.close(); } }