From 6fb261325aacf609a1257b62f51b00c07f6f396d Mon Sep 17 00:00:00 2001 From: Sander Deryckere Date: Wed, 15 Aug 2012 11:11:13 +0200 Subject: [PATCH] Always close stream --- .../src/net/osmand/plus/SpecialPhrases.java | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SpecialPhrases.java b/OsmAnd/src/net/osmand/plus/SpecialPhrases.java index d70d1bc5f7..0866ebc2f3 100644 --- a/OsmAnd/src/net/osmand/plus/SpecialPhrases.java +++ b/OsmAnd/src/net/osmand/plus/SpecialPhrases.java @@ -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,28 +53,33 @@ public class SpecialPhrases { m = new HashMap(); // The InputStream opens the resourceId and sends it to the buffer InputStream is = null; - 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)); - 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]); + 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"); } - - } + br = new BufferedReader(new InputStreamReader(is)); + String readLine = null; - // Close the InputStream and BufferedReader - is.close(); - br.close(); - + // 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]); + } + + } + + // Close the InputStream and BufferedReader + is.close(); + br.close(); + } finally { + Algoritms.closeStream(is); + Algoritms.closeStream(br); + } }