Close streams to avoid leakage

This commit is contained in:
Koen Rabaey 2013-09-21 23:11:55 +02:00
parent 52abab15bc
commit ce9584874f

View file

@ -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;
}