From cc3f2ecb075c48130637ce4813e11fa9d8c9d948 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 25 Feb 2015 22:15:41 -0500 Subject: [PATCH] Always close the cache output stream if an exception occurs --- .../computers/ComputerManagerService.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/limelight/computers/ComputerManagerService.java b/app/src/main/java/com/limelight/computers/ComputerManagerService.java index 72f4a3bb..a9c0873a 100644 --- a/app/src/main/java/com/limelight/computers/ComputerManagerService.java +++ b/app/src/main/java/com/limelight/computers/ComputerManagerService.java @@ -612,9 +612,19 @@ public class ComputerManagerService extends Service { List list = NvHTTP.getAppListByReader(new StringReader(appList)); if (appList != null && !appList.isEmpty() && !list.isEmpty()) { // Open the cache file - FileOutputStream cacheOut = CacheHelper.openCacheFileForOutput(getCacheDir(), "applist", computer.uuid.toString()); - CacheHelper.writeStringToOutputStream(cacheOut, appList); - cacheOut.close(); + FileOutputStream cacheOut = null; + try { + cacheOut = CacheHelper.openCacheFileForOutput(getCacheDir(), "applist", computer.uuid.toString()); + CacheHelper.writeStringToOutputStream(cacheOut, appList); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (cacheOut != null) { + cacheOut.close(); + } + } catch (IOException e) {} + } // Update the computer computer.rawAppList = appList;