You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by pr...@apache.org on 2016/03/17 08:27:58 UTC

lens git commit: LENS-953: Unclosed InputStream in DatabaseUtil#initializeDatabaseStorage()

Repository: lens
Updated Branches:
  refs/heads/master 8854cf512 -> e0c495e28


LENS-953: Unclosed InputStream in DatabaseUtil#initializeDatabaseStorage()


Project: http://git-wip-us.apache.org/repos/asf/lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/e0c495e2
Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/e0c495e2
Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/e0c495e2

Branch: refs/heads/master
Commit: e0c495e289a823517ad307ba8504766b7f709a48
Parents: 8854cf5
Author: Ajay Yadava <aj...@apache.org>
Authored: Thu Mar 17 12:57:27 2016 +0530
Committer: Rajat Khandelwal <ra...@gmail.com>
Committed: Thu Mar 17 12:57:27 2016 +0530

----------------------------------------------------------------------
 .../org/apache/lens/examples/DatabaseUtil.java  | 29 ++++++++++++--------
 1 file changed, 17 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lens/blob/e0c495e2/lens-examples/src/main/java/org/apache/lens/examples/DatabaseUtil.java
----------------------------------------------------------------------
diff --git a/lens-examples/src/main/java/org/apache/lens/examples/DatabaseUtil.java b/lens-examples/src/main/java/org/apache/lens/examples/DatabaseUtil.java
index f81504e..40632f8 100644
--- a/lens-examples/src/main/java/org/apache/lens/examples/DatabaseUtil.java
+++ b/lens-examples/src/main/java/org/apache/lens/examples/DatabaseUtil.java
@@ -40,7 +40,6 @@ public final class DatabaseUtil {
    * @throws Exception the exception
    */
   public static void initializeDatabaseStorage() throws Exception {
-
     try {
       Class.forName("org.hsqldb.jdbcDriver");
     } catch (ClassNotFoundException e) {
@@ -50,19 +49,25 @@ public final class DatabaseUtil {
 
     con.setAutoCommit(true);
     Statement statement = con.createStatement();
-
-    InputStream file = DatabaseUtil.class.getClassLoader().getResourceAsStream("db-storage-schema.sql");
-    BufferedReader reader = new BufferedReader(new InputStreamReader(file, "UTF-8"));
-    String line;
-    while ((line = reader.readLine()) != null) {
-      if (line.trim().equals("") || line.startsWith("--")) {
-        continue;
+    BufferedReader reader = null;
+    try {
+      InputStream file = DatabaseUtil.class.getClassLoader().getResourceAsStream("db-storage-schema.sql");
+      reader = new BufferedReader(new InputStreamReader(file, "UTF-8"));
+      String line;
+      while ((line = reader.readLine()) != null) {
+        if (line.trim().equals("") || line.startsWith("--")) {
+          continue;
+        }
+        statement.executeUpdate(line);
+      }
+    } finally {
+      if (reader != null) {
+        reader.close();
       }
-      statement.executeUpdate(line);
+      statement.execute("SHUTDOWN");
+      statement.close();
+      con.close();
     }
-    statement.execute("SHUTDOWN");
-    statement.close();
-    con.close();
   }
 
   /**