summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-02 19:49:01 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-02 19:49:01 +0200
commitc9ef24035ac3d7ad53881c35c12a2fe17ad0c415 (patch)
tree4942aa118aae4dfb184753abcce4d9656fbc348d
parent1ffe9168c9a753c1a9201998af83d9b12bda67c9 (diff)
downloadTwitterDataAnalytics-c9ef24035ac3d7ad53881c35c12a2fe17ad0c415.tar.gz
Abort if file cannot be read, don't leak on error
-rw-r--r--src/io/DataWriter.java28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/io/DataWriter.java b/src/io/DataWriter.java
index 2e90097..6a5e3fe 100644
--- a/src/io/DataWriter.java
+++ b/src/io/DataWriter.java
@@ -12,6 +12,7 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.Charsets;
+import org.apache.commons.io.IOUtils;
import org.json.JSONException;
import org.json.JSONObject;
import provider.ResultListener;
@@ -56,10 +57,20 @@ public class DataWriter implements ResultListener {
public DataWriter(final String profilesName, final String tweetsName)
throws IOException {
m_profile = getStore(profilesName);
- m_profileIdSet = readIds(m_profile);
-
+ try {
+ m_profileIdSet = readIds(m_profile);
+ } catch (IOException ex) {
+ m_profile.close();
+ throw ex;
+ }
m_tweet = getStore(profilesName);
- m_tweetIdSet = readIds(m_tweet);
+ try {
+ m_tweetIdSet = readIds(m_tweet);
+ } catch (IOException ex) {
+ m_profile.close();
+ m_tweet.close();
+ throw ex;
+ }
}
/**
@@ -112,15 +123,10 @@ public class DataWriter implements ResultListener {
// ignore, file will be created if necessary.
} catch (JSONException ex) {
getLogger().log(Level.WARNING, store.getFileName()
- + ": File is only partially processed", ex);
+ + ": Corrupt file?", ex);
+ throw new IOException(ex);
} finally {
- try {
- if (is != null) {
- is.close();
- }
- } catch (IOException ex) {
- getLogger().log(Level.WARNING, "Cannot close input file", ex);
- }
+ IOUtils.closeQuietly(is);
}
return idSet;
}