Browse Source

Properly close I/O streams that were not being properly closed

master
Anthony Restaino 9 years ago
parent
commit
7f965b0829
  1. 6
      app/src/main/java/acr/browser/lightning/database/BookmarkManager.java
  2. 5
      app/src/main/java/acr/browser/lightning/utils/AdBlock.java

6
app/src/main/java/acr/browser/lightning/database/BookmarkManager.java

@ -101,15 +101,14 @@ public class BookmarkManager { @@ -101,15 +101,14 @@ public class BookmarkManager {
final File bookmarksFile = new File(mFilesDir, FILE_BOOKMARKS);
BufferedReader bookmarksReader = null;
InputStream inputStream = null;
try {
final InputStream inputStream;
if (bookmarksFile.exists() && bookmarksFile.isFile()) {
inputStream = new FileInputStream(bookmarksFile);
} else {
inputStream = mContext.getResources().openRawResource(R.raw.default_bookmarks);
}
bookmarksReader =
new BufferedReader(new InputStreamReader(inputStream));
bookmarksReader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = bookmarksReader.readLine()) != null) {
try {
@ -130,6 +129,7 @@ public class BookmarkManager { @@ -130,6 +129,7 @@ public class BookmarkManager {
Log.e(TAG, "Error reading the bookmarks file", e);
} finally {
Utils.close(bookmarksReader);
Utils.close(inputStream);
}
mBookmarksMap = bookmarks;
mReady = true;

5
app/src/main/java/acr/browser/lightning/utils/AdBlock.java

@ -57,8 +57,9 @@ public class AdBlock { @@ -57,8 +57,9 @@ public class AdBlock {
@Override
public void run() {
AssetManager asset = context.getAssets();
BufferedReader reader = null;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
reader = new BufferedReader(new InputStreamReader(
asset.open(BLOCKED_DOMAINS_LIST_FILE_NAME)));
String line;
while ((line = reader.readLine()) != null) {
@ -67,6 +68,8 @@ public class AdBlock { @@ -67,6 +68,8 @@ public class AdBlock {
} catch (IOException e) {
Log.wtf(TAG, "Reading blocked domains list from file '"
+ BLOCKED_DOMAINS_LIST_FILE_NAME + "' failed.", e);
} finally {
Utils.close(reader);
}
}
});

Loading…
Cancel
Save