Always close the cache output stream if an exception occurs

This commit is contained in:
Cameron Gutman 2015-02-25 22:15:41 -05:00
parent 833b7c3916
commit cc3f2ecb07

View File

@ -612,9 +612,19 @@ public class ComputerManagerService extends Service {
List<NvApp> list = NvHTTP.getAppListByReader(new StringReader(appList)); List<NvApp> list = NvHTTP.getAppListByReader(new StringReader(appList));
if (appList != null && !appList.isEmpty() && !list.isEmpty()) { if (appList != null && !appList.isEmpty() && !list.isEmpty()) {
// Open the cache file // Open the cache file
FileOutputStream cacheOut = CacheHelper.openCacheFileForOutput(getCacheDir(), "applist", computer.uuid.toString()); FileOutputStream cacheOut = null;
CacheHelper.writeStringToOutputStream(cacheOut, appList); try {
cacheOut.close(); 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 // Update the computer
computer.rawAppList = appList; computer.rawAppList = appList;