Properly close I/O streams that were not being properly closed
This commit is contained in:
parent
5c8fd41c6b
commit
7f965b0829
@ -101,15 +101,14 @@ public class BookmarkManager {
|
|||||||
final File bookmarksFile = new File(mFilesDir, FILE_BOOKMARKS);
|
final File bookmarksFile = new File(mFilesDir, FILE_BOOKMARKS);
|
||||||
|
|
||||||
BufferedReader bookmarksReader = null;
|
BufferedReader bookmarksReader = null;
|
||||||
|
InputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
final InputStream inputStream;
|
|
||||||
if (bookmarksFile.exists() && bookmarksFile.isFile()) {
|
if (bookmarksFile.exists() && bookmarksFile.isFile()) {
|
||||||
inputStream = new FileInputStream(bookmarksFile);
|
inputStream = new FileInputStream(bookmarksFile);
|
||||||
} else {
|
} else {
|
||||||
inputStream = mContext.getResources().openRawResource(R.raw.default_bookmarks);
|
inputStream = mContext.getResources().openRawResource(R.raw.default_bookmarks);
|
||||||
}
|
}
|
||||||
bookmarksReader =
|
bookmarksReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||||
new BufferedReader(new InputStreamReader(inputStream));
|
|
||||||
String line;
|
String line;
|
||||||
while ((line = bookmarksReader.readLine()) != null) {
|
while ((line = bookmarksReader.readLine()) != null) {
|
||||||
try {
|
try {
|
||||||
@ -130,6 +129,7 @@ public class BookmarkManager {
|
|||||||
Log.e(TAG, "Error reading the bookmarks file", e);
|
Log.e(TAG, "Error reading the bookmarks file", e);
|
||||||
} finally {
|
} finally {
|
||||||
Utils.close(bookmarksReader);
|
Utils.close(bookmarksReader);
|
||||||
|
Utils.close(inputStream);
|
||||||
}
|
}
|
||||||
mBookmarksMap = bookmarks;
|
mBookmarksMap = bookmarks;
|
||||||
mReady = true;
|
mReady = true;
|
||||||
|
@ -57,8 +57,9 @@ public class AdBlock {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
AssetManager asset = context.getAssets();
|
AssetManager asset = context.getAssets();
|
||||||
|
BufferedReader reader = null;
|
||||||
try {
|
try {
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
reader = new BufferedReader(new InputStreamReader(
|
||||||
asset.open(BLOCKED_DOMAINS_LIST_FILE_NAME)));
|
asset.open(BLOCKED_DOMAINS_LIST_FILE_NAME)));
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
@ -67,6 +68,8 @@ public class AdBlock {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.wtf(TAG, "Reading blocked domains list from file '"
|
Log.wtf(TAG, "Reading blocked domains list from file '"
|
||||||
+ BLOCKED_DOMAINS_LIST_FILE_NAME + "' failed.", e);
|
+ BLOCKED_DOMAINS_LIST_FILE_NAME + "' failed.", e);
|
||||||
|
} finally {
|
||||||
|
Utils.close(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user