This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push: new d74eb1ce92 For transformations requiring datum shift grids, if the `SIS_DATA` environment variable is not set, report the file as missing instead of throwing an exception telling that the URI is not absolute. This is necessary for letting the caller fallbacks on alternative transformation methods. d74eb1ce92 is described below commit d74eb1ce921ed6d8b738d784cb24ffabd18d2e21 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Wed Feb 1 12:06:40 2023 +0100 For transformations requiring datum shift grids, if the `SIS_DATA` environment variable is not set, report the file as missing instead of throwing an exception telling that the URI is not absolute. This is necessary for letting the caller fallbacks on alternative transformation methods. --- .../referencing/provider/DatumShiftGridLoader.java | 22 +++++++++++++++++++++- .../provider/FranceGeocentricInterpolation.java | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridLoader.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridLoader.java index 8e046fdd86..00968b55a6 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridLoader.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/DatumShiftGridLoader.java @@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.io.EOFException; import java.io.IOException; import java.net.URI; +import java.net.URL; import java.nio.ByteBuffer; import java.nio.file.Path; import java.nio.file.Paths; @@ -165,6 +166,25 @@ abstract class DatumShiftGridLoader { return path; } + /** + * Converts the given path to a URL, throwing a {@link NoSuchFileException} if the URL is not absolute. + * This specific exception type is necessary for letting the caller know that the coordinate operation is + * probably valid but can not be constructed because an optional configuration is missing. + * It is typically because the {@code SIS_DATA} environment variable has not been set. + * + * @param path the path to convert to a URL. + * @return the given path as an URL. + * @throws NoSuchFileException if the URI is not absolute. + * @throws java.net.MalformedURLException if some error occurred during the conversion. + */ + static URL toURL(final URI path) throws IOException { + try { + return path.toURL(); + } catch (IllegalArgumentException e) { + throw new NoSuchFileException(path.toString(), null, e.getMessage()); + } + } + /** * Creates a channel for reading bytes from the file at the specified path. * @@ -178,7 +198,7 @@ abstract class DatumShiftGridLoader { } catch (FileSystemNotFoundException e) { Logging.ignorableException(AbstractProvider.LOGGER, DatumShiftGridLoader.class, "newByteChannel", e); } - return Channels.newChannel(path.toURL().openStream()); + return Channels.newChannel(toURL(path).openStream()); } /** diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java index b5160c1f1c..f6105ef4cc 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/FranceGeocentricInterpolation.java @@ -395,7 +395,7 @@ public class FranceGeocentricInterpolation extends GeodeticOperation { /** Returns the reader for the specified URI. */ static BufferedReader newBufferedReader(final URI file) throws IOException { - return new BufferedReader(new InputStreamReader(file.toURL().openStream())); + return new BufferedReader(new InputStreamReader(DatumShiftGridLoader.toURL(file).openStream())); } /**