Bug 710864 - Close stream after we're done with it. r=blassey
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 15 Dec 2011 10:46:36 -0500
changeset 82670 1eff10689611144cee136bbf06613a8ff6448a79
parent 82669 635b238dfc2ce0df59757fe6048ad61e38fd27b4
child 82671 bbb2149b613ebaaa3b5b7acde9769a62f8bd0856
push id4052
push userbmo@edmorley.co.uk
push dateThu, 15 Dec 2011 17:28:45 +0000
treeherdermozilla-inbound@f776e38057b1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs710864
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 710864 - Close stream after we're done with it. r=blassey
mobile/android/base/AboutHomeContent.java
--- a/mobile/android/base/AboutHomeContent.java
+++ b/mobile/android/base/AboutHomeContent.java
@@ -37,16 +37,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 package org.mozilla.gecko;
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
+import java.io.IOException;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.BrowserDB.URLColumns;
 
@@ -248,19 +249,29 @@ public class AboutHomeContent extends Sc
         GeckoAppShell.getHandler().post(new Runnable() {
             public void run() {
                 try {
                     byte[] buf = new byte[32768];
                     InputStream fileStream = getRecommendedAddonsStream(activity);
                     if (fileStream == null)
                         return;
                     StringBuffer jsonString = new StringBuffer();
-                    int read = 0;
-                    while ((read = fileStream.read(buf, 0, 32768)) != -1) {
-                        jsonString.append(new String(buf, 0, read));
+                    try {
+                        int read = 0;
+                        while ((read = fileStream.read(buf, 0, 32768)) != -1) {
+                            jsonString.append(new String(buf, 0, read));
+                        }
+                    } finally {
+                        try {
+                            fileStream.close();
+                        } catch (IOException ioe) {
+                            // catch this here because we can continue even if the
+                            // close failed
+                            Log.i(LOGTAG, "error closing json file", ioe);
+                        }
                     }
                     final JSONArray array = new JSONObject(jsonString.toString()).getJSONArray("addons");
                     GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
                         public void run() {
                             try {
                                 for (int i = 0; i < array.length(); i++) {
                                     JSONObject jsonobj = array.getJSONObject(i);
                                     mAddonsAdapter.add(jsonobj.getString("name"));