From ce9584874f851c2def6bbc766482d12916934153 Mon Sep 17 00:00:00 2001 From: Koen Rabaey Date: Sat, 21 Sep 2013 23:11:55 +0200 Subject: [PATCH] Close streams to avoid leakage --- .../net/osmand/router/RoutingConfiguration.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java b/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java index 7090da5583..3e40e48645 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java +++ b/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java @@ -1,12 +1,10 @@ package net.osmand.router; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.LinkedHashMap; import java.util.Map; -import net.osmand.Collator; import net.osmand.PlatformUtil; import net.osmand.router.GeneralRouter.GeneralRouterProfile; import net.osmand.util.Algorithms; @@ -120,11 +118,21 @@ public class RoutingConfiguration { public static RoutingConfiguration.Builder getDefault() { if (DEFAULT == null) { + InputStream resourceAsStream = null; try { - DEFAULT = parseFromInputStream(RoutingConfiguration.class.getResourceAsStream("routing.xml")); + resourceAsStream = RoutingConfiguration.class.getResourceAsStream("routing.xml"); + DEFAULT = parseFromInputStream(resourceAsStream); } catch (Exception e) { throw new IllegalStateException(e); - } + } finally { + if (resourceAsStream != null) { + try { + resourceAsStream.close(); + } catch (IOException ignore) { + // + } + } + } } return DEFAULT; }