From 41475d570b891d2af3a541298fd89a4c0dfb4ab5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20D=C3=B6rre?= Date: Thu, 7 Jul 2016 09:02:45 +0200 Subject: [PATCH] upd: minor fixup on highFinancialValue code Change-Id: I77914e4705371f0980bf9592bb506f033a881505 --- config/gigi.properties.template | 2 +- .../gigi/util/HighFinancialValueFetcher.java | 33 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/config/gigi.properties.template b/config/gigi.properties.template index a6406a1e..c34fff17 100644 --- a/config/gigi.properties.template +++ b/config/gigi.properties.template @@ -15,4 +15,4 @@ sql.url=jdbc:postgresql://localhost/cacert sql.user= sql.password= -highFinancialValue=/path/to/alexa/list \ No newline at end of file +highFinancialValue=/path/to/alexa/list 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(); } } -- 2.39.2