changeset 158:d558a9a44d5b

Close streams after we're finished using them.
author Denis Lila <dlila@redhat.com>
date Tue, 08 Mar 2011 14:48:34 -0500
parents 6dd840d6a04d
children 67ae546b6605
files ChangeLog netx/net/sourceforge/jnlp/browser/FirefoxPreferencesFinder.java netx/net/sourceforge/jnlp/browser/FirefoxPreferencesParser.java netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java netx/net/sourceforge/jnlp/security/CertWarningPane.java netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java
diffstat 6 files changed, 101 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Mar 08 10:11:28 2011 -0500
+++ b/ChangeLog	Tue Mar 08 14:48:34 2011 -0500
@@ -1,3 +1,16 @@
+2011-03-08  Denis Lila  <dlila@redhat.com>
+
+	* netx/net/sourceforge/jnlp/browser/FirefoxPreferencesFinder.java
+	(find): Close input stream.
+	* netx/net/sourceforge/jnlp/browser/FirefoxPreferencesParser.java
+	(parse): Close input stream.
+	* netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java
+	(getPacContents, getHelperFunctionContents): Close input stream.
+	* netx/net/sourceforge/jnlp/security/CertWarningPane.java
+	(CheckBoxListener.actionPerformed): Close output stream.
+	* netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java
+	(ImportButtonListener.actionPerformed): Close output stream.
+
 2011-03-08  Andrew Su  <asu@redhat.com>
 
 	* netx/net/sourceforge/jnlp/util/PropertiesFile.java:
--- a/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesFinder.java	Tue Mar 08 10:11:28 2011 -0500
+++ b/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesFinder.java	Tue Mar 08 14:48:34 2011 -0500
@@ -85,31 +85,34 @@
          */
 
         // find the section with an entry Default=1
-        while (true) {
-            String line = reader.readLine();
-            if (line == null) {
-                break;
-            }
-
-            line = line.trim();
-            if (line.startsWith("[") && line.endsWith("]")) {
-                if (foundDefaultSection) {
+        try {
+            while (true) {
+                String line = reader.readLine();
+                if (line == null) {
                     break;
                 }
-                // new section
-                linesInSection = new ArrayList<String>();
-            } else {
-                linesInSection.add(line);
-                int equalSignPos = line.indexOf('=');
-                if (equalSignPos > 0) {
-                    String key = line.substring(0, equalSignPos).trim();
-                    String value = line.substring(equalSignPos+1).trim();
-                    if (key.toLowerCase().equals("default") && value.equals("1")) {
-                        foundDefaultSection = true;
+
+                line = line.trim();
+                if (line.startsWith("[") && line.endsWith("]")) {
+                    if (foundDefaultSection) {
+                        break;
+                    }
+                    // new section
+                    linesInSection = new ArrayList<String>();
+                } else {
+                    linesInSection.add(line);
+                    int equalSignPos = line.indexOf('=');
+                    if (equalSignPos > 0) {
+                        String key = line.substring(0, equalSignPos).trim();
+                        String value = line.substring(equalSignPos+1).trim();
+                        if (key.toLowerCase().equals("default") && value.equals("1")) {
+                            foundDefaultSection = true;
+                        }
                     }
                 }
             }
-
+        } finally {
+            reader.close();
         }
 
         if (!foundDefaultSection) {
--- a/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesParser.java	Tue Mar 08 10:11:28 2011 -0500
+++ b/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesParser.java	Tue Mar 08 14:48:34 2011 -0500
@@ -87,52 +87,56 @@
 
         BufferedReader reader = new BufferedReader(new FileReader(prefsFile));
 
-        while (true) {
-            String line = reader.readLine();
-            // end of stream
-            if (line == null) {
-                break;
-            }
+        try {
+            while (true) {
+                String line = reader.readLine();
+                // end of stream
+                if (line == null) {
+                    break;
+                }
 
-            line = line.trim();
-            if (line.startsWith("user_pref")) {
+                line = line.trim();
+                if (line.startsWith("user_pref")) {
 
-                /*
-                 * each line is of the form: user_pref("key",value); where value
-                 * can be a string in double quotes or an integer or float or
-                 * boolean
-                 */
+                    /*
+                     * each line is of the form: user_pref("key",value); where value
+                     * can be a string in double quotes or an integer or float or
+                     * boolean
+                     */
 
-                boolean foundKey = false;
-                boolean foundValue = false;
+                    boolean foundKey = false;
+                    boolean foundValue = false;
 
-                // extract everything inside user_pref( and );
-                String pref = line.substring("user_pref(".length(), line.length() - 2);
-                // key and value are separated by a ,
-                int firstCommaPos = pref.indexOf(',');
-                if (firstCommaPos >= 1) {
-                    String key = pref.substring(0, firstCommaPos).trim();
-                    if (key.startsWith("\"") && key.endsWith("\"")) {
-                        key = key.substring(1, key.length() - 1);
-                        if (key.trim().length() > 0) {
-                            foundKey = true;
+                    // extract everything inside user_pref( and );
+                    String pref = line.substring("user_pref(".length(), line.length() - 2);
+                    // key and value are separated by a ,
+                    int firstCommaPos = pref.indexOf(',');
+                    if (firstCommaPos >= 1) {
+                        String key = pref.substring(0, firstCommaPos).trim();
+                        if (key.startsWith("\"") && key.endsWith("\"")) {
+                            key = key.substring(1, key.length() - 1);
+                            if (key.trim().length() > 0) {
+                                foundKey = true;
+                            }
                         }
-                    }
 
-                    if (pref.length() > firstCommaPos + 1) {
-                        String value = pref.substring(firstCommaPos + 1).trim();
-                        if (value.startsWith("\"") && value.endsWith("\"")) {
-                            value = value.substring(1, value.length() - 1).trim();
-                        }
-                        foundValue = true;
+                        if (pref.length() > firstCommaPos + 1) {
+                            String value = pref.substring(firstCommaPos + 1).trim();
+                            if (value.startsWith("\"") && value.endsWith("\"")) {
+                                value = value.substring(1, value.length() - 1).trim();
+                            }
+                            foundValue = true;
 
-                        if (foundKey && foundValue) {
-                            // System.out.println("added (\"" + key + "\", \"" + value + "\")");
-                            prefs.put(key, value);
+                            if (foundKey && foundValue) {
+                                // System.out.println("added (\"" + key + "\", \"" + value + "\")");
+                                prefs.put(key, value);
+                            }
                         }
                     }
                 }
             }
+        } finally {
+            reader.close();
         }
         if (JNLPRuntime.isDebug()) {
             System.out.println("Read " + prefs.size() + " entries from Firefox's preferences");
--- a/netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java	Tue Mar 08 10:11:28 2011 -0500
+++ b/netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java	Tue Mar 08 14:48:34 2011 -0500
@@ -140,11 +140,15 @@
         StringBuilder contents = null;
         try {
             String line = null;
+            contents = new StringBuilder();
             BufferedReader pacReader = new BufferedReader(new InputStreamReader(pacUrl.openStream()));
-            contents = new StringBuilder();
-            while ((line = pacReader.readLine()) != null) {
-                // System.out.println(line);
-                contents = contents.append(line).append("\n");
+            try {
+                while ((line = pacReader.readLine()) != null) {
+                    // System.out.println(line);
+                    contents = contents.append(line).append("\n");
+                }
+            } finally {
+                pacReader.close();
             }
         } catch (IOException e) {
             contents = null;
@@ -167,10 +171,14 @@
             }
             InputStream in = cl.getResourceAsStream("net/sourceforge/jnlp/runtime/pac-funcs.js");
             BufferedReader pacFuncsReader = new BufferedReader(new InputStreamReader(in));
-            contents = new StringBuilder();
-            while ((line = pacFuncsReader.readLine()) != null) {
-                // System.out.println(line);
-                contents = contents.append(line).append("\n");
+            try {
+                contents = new StringBuilder();
+                while ((line = pacFuncsReader.readLine()) != null) {
+                    // System.out.println(line);
+                    contents = contents.append(line).append("\n");
+                }
+            } finally {
+                pacFuncsReader.close();
             }
         } catch (IOException e) {
             e.printStackTrace();
--- a/netx/net/sourceforge/jnlp/security/CertWarningPane.java	Tue Mar 08 10:11:28 2011 -0500
+++ b/netx/net/sourceforge/jnlp/security/CertWarningPane.java	Tue Mar 08 14:48:34 2011 -0500
@@ -252,7 +252,11 @@
                     }
 
                     OutputStream os = new FileOutputStream(keyStoreFile);
-                    ks.store(os, KeyStores.getPassword());
+                    try {
+                        ks.store(os, KeyStores.getPassword());
+                    } finally {
+                        os.close();
+                    }
                     if (JNLPRuntime.isDebug()) {
                         System.out.println("certificate is now permanently trusted");
                     }
--- a/netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java	Tue Mar 08 10:11:28 2011 -0500
+++ b/netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java	Tue Mar 08 14:48:34 2011 -0500
@@ -369,7 +369,11 @@
                     }
 
                     OutputStream os = new FileOutputStream(keyStoreFile);
-                    ks.store(os, KeyStores.getPassword());
+                    try {
+                        ks.store(os, KeyStores.getPassword());
+                    } finally {
+                        os.close();
+                    }
                     repopulateTables();
                 } catch (Exception ex) {
                     // TODO: handle exception