Always close stream
This commit is contained in:
parent
2aa87f74cc
commit
6fb261325a
1 changed files with 27 additions and 20 deletions
|
@ -8,6 +8,8 @@ import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.osmand.Algoritms;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.AssetManager;
|
import android.content.res.AssetManager;
|
||||||
|
|
||||||
|
@ -51,28 +53,33 @@ public class SpecialPhrases {
|
||||||
m = new HashMap<String,String>();
|
m = new HashMap<String,String>();
|
||||||
// The InputStream opens the resourceId and sends it to the buffer
|
// The InputStream opens the resourceId and sends it to the buffer
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
BufferedReader br = null;
|
||||||
is = ctx.getAssets().open("specialphrases/specialphrases_"+lang+".txt");
|
try{
|
||||||
} catch (IOException ex) {
|
try {
|
||||||
// second try: default to English, if this fails, the error is thrown outside
|
is = ctx.getAssets().open("specialphrases/specialphrases_"+lang+".txt");
|
||||||
is = ctx.getAssets().open("specialphrases/specialphrases_en.txt");
|
} catch (IOException ex) {
|
||||||
}
|
// second try: default to English, if this fails, the error is thrown outside
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
is = ctx.getAssets().open("specialphrases/specialphrases_en.txt");
|
||||||
String readLine = null;
|
|
||||||
|
|
||||||
// While the BufferedReader readLine is not null
|
|
||||||
while ((readLine = br.readLine()) != null) {
|
|
||||||
String[] arr = readLine.split(",");
|
|
||||||
if (arr != null && arr.length == 2) {
|
|
||||||
m.put(arr[0], arr[1]);
|
|
||||||
}
|
}
|
||||||
|
br = new BufferedReader(new InputStreamReader(is));
|
||||||
}
|
String readLine = null;
|
||||||
|
|
||||||
// Close the InputStream and BufferedReader
|
// While the BufferedReader readLine is not null
|
||||||
is.close();
|
while ((readLine = br.readLine()) != null) {
|
||||||
br.close();
|
String[] arr = readLine.split(",");
|
||||||
|
if (arr != null && arr.length == 2) {
|
||||||
|
m.put(arr[0], arr[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the InputStream and BufferedReader
|
||||||
|
is.close();
|
||||||
|
br.close();
|
||||||
|
} finally {
|
||||||
|
Algoritms.closeStream(is);
|
||||||
|
Algoritms.closeStream(br);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue