diff options
author | Denis Lila <[email protected]> | 2011-03-08 14:48:34 -0500 |
---|---|---|
committer | Denis Lila <[email protected]> | 2011-03-08 14:48:34 -0500 |
commit | 7402c4e21bd5da0b1e66da01b96a3fd9cd24e10e (patch) | |
tree | 17c6cf70ea92c253f85eac144a82798a0659995e /netx/net/sourceforge | |
parent | 261b0560100e15e376cb6bcf64eaabb5a79b24c5 (diff) |
Close streams after we're finished using them.
Diffstat (limited to 'netx/net/sourceforge')
5 files changed, 92 insertions, 69 deletions
diff --git a/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesFinder.java b/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesFinder.java index 34d1092..45f6faa 100644 --- a/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesFinder.java +++ b/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesFinder.java @@ -85,31 +85,34 @@ public class FirefoxPreferencesFinder { */ // 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) { diff --git a/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesParser.java b/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesParser.java index 1f206a9..9555b00 100644 --- a/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesParser.java +++ b/netx/net/sourceforge/jnlp/browser/FirefoxPreferencesParser.java @@ -87,52 +87,56 @@ public final class FirefoxPreferencesParser { BufferedReader reader = new BufferedReader(new FileReader(prefsFile)); - while (true) { - String line = reader.readLine(); - // end of stream - if (line == null) { - break; - } - - 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 - */ - - 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; - } - } + try { + while (true) { + String line = reader.readLine(); + // end of stream + if (line == null) { + break; + } - 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(); + 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 + */ + + 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; + } } - foundValue = true; - if (foundKey && foundValue) { - // System.out.println("added (\"" + key + "\", \"" + value + "\")"); - prefs.put(key, value); + 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); + } } } } } + } finally { + reader.close(); } if (JNLPRuntime.isDebug()) { System.out.println("Read " + prefs.size() + " entries from Firefox's preferences"); diff --git a/netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java b/netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java index d5e4ffb..e08feb2 100644 --- a/netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java +++ b/netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java @@ -140,11 +140,15 @@ public class RhinoBasedPacEvaluator implements PacEvaluator { StringBuilder contents = null; try { String line = null; - 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"); + BufferedReader pacReader = new BufferedReader(new InputStreamReader(pacUrl.openStream())); + 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 @@ public class RhinoBasedPacEvaluator implements PacEvaluator { } 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(); diff --git a/netx/net/sourceforge/jnlp/security/CertWarningPane.java b/netx/net/sourceforge/jnlp/security/CertWarningPane.java index fcee971..383120d 100644 --- a/netx/net/sourceforge/jnlp/security/CertWarningPane.java +++ b/netx/net/sourceforge/jnlp/security/CertWarningPane.java @@ -252,7 +252,11 @@ public class CertWarningPane extends SecurityDialogPanel { } 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"); } diff --git a/netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java b/netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java index ed71d0d..db4e0cb 100644 --- a/netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java +++ b/netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java @@ -369,7 +369,11 @@ public class CertificatePane extends JPanel { } 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 |