summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-02 18:39:21 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-02 18:39:21 +0200
commitcd1e712c055deb6260e70a38bb4a9a8c032c7ea4 (patch)
tree43bfaf5c54b5c4a3257ceec91ef4339d7c09256d
parent7a645cb4f73bf697d166ede24e81f0d56f5b68b3 (diff)
downloadTwitterDataAnalytics-cd1e712c055deb6260e70a38bb4a9a8c032c7ea4.tar.gz
DataWriter: don't leak input fd
-rw-r--r--src/io/DataWriter.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/io/DataWriter.java b/src/io/DataWriter.java
index d762fee..2e90097 100644
--- a/src/io/DataWriter.java
+++ b/src/io/DataWriter.java
@@ -97,8 +97,9 @@ public class DataWriter implements ResultListener {
*/
private Set<Long> readIds(Store store) throws IOException {
Set<Long> idSet = new HashSet<>();
+ InputStream is = null;
try {
- InputStream is = store.getInputStream();
+ is = store.getInputStream();
Scanner reader = new Scanner(is);
// parse each line into a JSONObject, read the id and add it to
// the set of ids.
@@ -112,6 +113,14 @@ public class DataWriter implements ResultListener {
} catch (JSONException ex) {
getLogger().log(Level.WARNING, store.getFileName()
+ ": File is only partially processed", ex);
+ } finally {
+ try {
+ if (is != null) {
+ is.close();
+ }
+ } catch (IOException ex) {
+ getLogger().log(Level.WARNING, "Cannot close input file", ex);
+ }
}
return idSet;
}