Always close stream

This commit is contained in:
Sander Deryckere 2012-08-15 11:11:13 +02:00
parent 2aa87f74cc
commit 6fb261325a

View file

@ -8,6 +8,8 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import net.osmand.Algoritms;
import android.content.Context;
import android.content.res.AssetManager;
@ -51,13 +53,15 @@ public class SpecialPhrases {
m = new HashMap<String,String>();
// The InputStream opens the resourceId and sends it to the buffer
InputStream is = null;
BufferedReader br = null;
try{
try {
is = ctx.getAssets().open("specialphrases/specialphrases_"+lang+".txt");
} catch (IOException ex) {
// second try: default to English, if this fails, the error is thrown outside
is = ctx.getAssets().open("specialphrases/specialphrases_en.txt");
}
BufferedReader br = new BufferedReader(new InputStreamReader(is));
br = new BufferedReader(new InputStreamReader(is));
String readLine = null;
// While the BufferedReader readLine is not null
@ -72,7 +76,10 @@ public class SpecialPhrases {
// Close the InputStream and BufferedReader
is.close();
br.close();
} finally {
Algoritms.closeStream(is);
Algoritms.closeStream(br);
}
}