From e41eb9836f75c642f637b4dd32baa7355439d03e Mon Sep 17 00:00:00 2001 From: nicolas-f <1382241+nicolas-f@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:36:04 +0200 Subject: [PATCH] About #613 handle wrong file extension with a more explicit error --- .../wps/Import_and_Export/Import_OSM.groovy | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Import_and_Export/Import_OSM.groovy b/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Import_and_Export/Import_OSM.groovy index b0304ab24..19e7be212 100644 --- a/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Import_and_Export/Import_OSM.groovy +++ b/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Import_and_Export/Import_OSM.groovy @@ -215,13 +215,15 @@ def exec(Connection connection, input) { // Read the OSM file, depending on its extension def reader - if (pathFile.endsWith(".pbf")) { + if (pathFile.toLowerCase(Locale.getDefault()).endsWith(".pbf")) { InputStream inputStream = new FileInputStream(pathFile); reader = new OsmosisReader(inputStream); - } else if (pathFile.endsWith(".osm")) { + } else if (pathFile.toLowerCase(Locale.getDefault()).endsWith(".osm")) { reader = new XmlReader(new File(pathFile), true, CompressionMethod.None); - } else if (pathFile.endsWith(".osm.gz")) { + } else if (pathFile.toLowerCase(Locale.getDefault()).endsWith(".osm.gz")) { reader = new XmlReader(new File(pathFile), true, CompressionMethod.GZip); + } else { + throw new IllegalArgumentException("File extension not known.Should be pbf, osm or osm.gz but got " + pathFile) } OsmHandler handler = new OsmHandler(logger, ignoreBuilding, ignoreRoads, ignoreGround, removeTunnels)