Index: trunk/scripts/BuildProjectionDefinitions.java
===================================================================
--- trunk/scripts/BuildProjectionDefinitions.java	(revision 14637)
+++ trunk/scripts/BuildProjectionDefinitions.java	(revision 14638)
@@ -1,12 +1,12 @@
 // License: GPL. For details, see LICENSE file.
 
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
+import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
+import java.io.Writer;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -16,4 +16,5 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 import org.openstreetmap.josm.data.projection.CustomProjection;
@@ -43,17 +44,17 @@
 
     // statistics:
-    private static int noInJosm = 0;
-    private static int noInProj4 = 0;
-    private static int noDeprecated = 0;
-    private static int noGeocent = 0;
-    private static int noBaseProjection = 0;
-    private static int noEllipsoid = 0;
-    private static int noNadgrid = 0;
-    private static int noDatumgrid = 0;
-    private static int noJosm = 0;
-    private static int noProj4 = 0;
-    private static int noEsri = 0;
-    private static int noOmercNoBounds = 0;
-    private static int noEquatorStereo = 0;
+    private static int noInJosm;
+    private static int noInProj4;
+    private static int noDeprecated;
+    private static int noGeocent;
+    private static int noBaseProjection;
+    private static int noEllipsoid;
+    private static int noNadgrid;
+    private static int noDatumgrid;
+    private static int noJosm;
+    private static int noProj4;
+    private static int noEsri;
+    private static int noOmercNoBounds;
+    private static int noEquatorStereo;
 
     private static final Map<String, Integer> baseProjectionMap = new TreeMap<>();
@@ -77,13 +78,17 @@
     }
 
-    static List<String> initList(String baseDir, String ext) {
-        String[] result = new File(baseDir + File.separator + PROJ_DIR)
-                .list((dir, name) -> !name.contains(".") || name.toLowerCase(Locale.ENGLISH).endsWith(ext));
-        return result != null ? Arrays.asList(result) : Collections.emptyList();
+    static List<String> initList(String baseDir, String ext) throws IOException {
+        return Files.list(Paths.get(baseDir).resolve(PROJ_DIR))
+                .map(path -> path.getFileName().toString())
+                .filter(name -> !name.contains(".") || name.toLowerCase(Locale.ENGLISH).endsWith(ext))
+                .collect(Collectors.toList());
     }
 
     static void initMap(String baseDir, String file, Map<String, ProjectionDefinition> map) throws IOException {
-        List<ProjectionDefinition> list = Projections.loadProjectionDefinitions(
-                baseDir + File.separator + PROJ_DIR + File.separator + file);
+        final Path path = Paths.get(baseDir).resolve(PROJ_DIR).resolve(file);
+        final List<ProjectionDefinition> list;
+        try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
+            list = Projections.loadProjectionDefinitions(reader);
+        }
         if (list.isEmpty())
             throw new AssertionError("EPSG file seems corrupted");
@@ -109,6 +114,5 @@
         knownNadgrids = initList(baseDir, ".gsb");
 
-        try (FileOutputStream output = new FileOutputStream(baseDir + File.separator + OUTPUT_EPSG_FILE);
-             BufferedWriter out = new BufferedWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8))) {
+        try (Writer out = Files.newBufferedWriter(Paths.get(baseDir).resolve(OUTPUT_EPSG_FILE), StandardCharsets.UTF_8)) {
             out.write("## This file is autogenerated, do not edit!\n");
             out.write("## Run ant task \"epsg\" to rebuild.\n");
@@ -180,5 +184,5 @@
     }
 
-    static void write(BufferedWriter out, ProjectionDefinition pd) throws IOException {
+    static void write(Writer out, ProjectionDefinition pd) throws IOException {
         out.write("# " + pd.name + "\n");
         out.write("<"+pd.code.substring("EPSG:".length())+"> "+pd.definition+" <>\n");
@@ -246,5 +250,5 @@
             parameters = CustomProjection.parseParameterList(pd.definition, true);
         } catch (ProjectionConfigurationException ex) {
-            throw new RuntimeException(pd.code+":"+ex);
+            throw new IllegalStateException(pd.code + ":" + ex, ex);
         }
         String proj = parameters.get(CustomProjection.Param.proj.key);
@@ -306,5 +310,5 @@
         }
 
-        final double EPS10 = 1.e-10;
+        final double eps10 = 1.e-10;
 
         String lat0 = parameters.get("lat_0");
@@ -313,5 +317,5 @@
                 final double latitudeOfOrigin = Math.toRadians(CustomProjection.parseAngle(lat0, Param.lat_0.key));
                 // TODO: implement equatorial stereographic, see https://josm.openstreetmap.de/ticket/15970
-                if (result && "stere".equals(proj) && Math.abs(latitudeOfOrigin) < EPS10) {
+                if (result && "stere".equals(proj) && Math.abs(latitudeOfOrigin) < eps10) {
                     result = false;
                     noEquatorStereo++;
@@ -320,7 +324,7 @@
                 // exclude entries which need geodesic computation (equatorial/oblique azimuthal equidistant)
                 if (result && "aeqd".equals(proj)) {
-                    final double HALF_PI = Math.PI / 2;
-                    if (Math.abs(latitudeOfOrigin - HALF_PI) >= EPS10 &&
-                        Math.abs(latitudeOfOrigin + HALF_PI) >= EPS10) {
+                    final double halfPi = Math.PI / 2;
+                    if (Math.abs(latitudeOfOrigin - halfPi) >= eps10 &&
+                        Math.abs(latitudeOfOrigin + halfPi) >= eps10) {
                         // See https://josm.openstreetmap.de/ticket/16129#comment:21
                         result = false;
@@ -338,6 +342,6 @@
         }
 
-        String k_0 = parameters.get("k_0");
-        if (result && k_0 != null && k_0.startsWith("-")) {
+        String k0 = parameters.get("k_0");
+        if (result && k0 != null && k0.startsWith("-")) {
             // Proj fails with "k <= 0" for ESRI:102470
             result = false;
