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
commit 51dcbb130513605dfad85c85c5028643af69164b Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Mon Dec 25 19:55:14 2023 +0100 Add `public` and `protected` modifiers to `DatumShiftGridLoader` methods. It does not make practical difference because the class is package-private. However, they are hints about which methods are invoked by classes other than sub-classes. --- .../operation/provider/DatumShiftGridLoader.java | 29 +++++++++++++--------- .../sis/referencing/operation/provider/NADCON.java | 4 +-- .../sis/referencing/operation/provider/NTv2.java | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/DatumShiftGridLoader.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/DatumShiftGridLoader.java index f62315ac6e..516e7b804e 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/DatumShiftGridLoader.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/DatumShiftGridLoader.java @@ -50,7 +50,7 @@ abstract class DatumShiftGridLoader { /** * Conversion factor from degrees to seconds. */ - static final double DEGREES_TO_SECONDS = 3600; + protected static final double DEGREES_TO_SECONDS = 3600; /** * Possible precision for offset values in seconds of angle. This value is used only as a hint @@ -67,12 +67,12 @@ abstract class DatumShiftGridLoader { * We use a value of 1E-4 because more accurate values tend to cause overflows in the compression algorithm, * in which case the compression fails. With a more reasonable value, we have better chances of success. */ - static final double SECOND_PRECISION = 1E-4; + protected static final double SECOND_PRECISION = 1E-4; /** * The file to load, used for parameter declaration and if we have errors to report. */ - final URI file; + protected final URI file; /** * The channel opened on the file. @@ -82,7 +82,7 @@ abstract class DatumShiftGridLoader { /** * The buffer to use for transferring data from the channel. */ - final ByteBuffer buffer; + protected final ByteBuffer buffer; /** * Whether the tip about the location of datum shift files has been logged. @@ -114,7 +114,7 @@ abstract class DatumShiftGridLoader { * @throws EOFException if the channel has reached the end of stream. * @throws IOException if another kind of error occurred while reading. */ - final void ensureBufferContains(int n) throws IOException { + protected final void ensureBufferContains(int n) throws IOException { assert n >= 0 && n <= buffer.capacity() : n; n -= buffer.remaining(); if (n > 0) { @@ -136,8 +136,10 @@ abstract class DatumShiftGridLoader { /** * Skips exactly <var>n</var> bytes. + * + * @param n the number of bytes to skip. */ - final void skip(int n) throws IOException { + protected final void skip(int n) throws IOException { int p; while ((p = buffer.position() + n) > buffer.limit()) { n -= buffer.remaining(); @@ -182,12 +184,13 @@ abstract class DatumShiftGridLoader { /** * Creates a channel for reading bytes from the file at the specified path. + * This method tries to open using the file system before to open from the URL. * * @param path the path from where to read bytes. * @return a channel for reading bytes from the given path. * @throws IOException if the channel cannot be created. */ - static ReadableByteChannel newByteChannel(final URI path) throws IOException { + public static ReadableByteChannel newByteChannel(final URI path) throws IOException { try { return Files.newByteChannel(Path.of(path)); } catch (FileSystemNotFoundException e) { @@ -198,23 +201,25 @@ abstract class DatumShiftGridLoader { /** * Logs a message about a grid which is about to be loaded. + * The logger will be {@code "org.apache.sis.referencing.operation"} and the originating + * method will be {@code "createMathTransform"} in the specified {@code caller} class. * * @param caller the provider to logs as the source class. - * the source method will be set to {@code "createMathTransform"}. * @param file the grid file, as a {@link String} or a {@link URI}. */ - static void startLoading(final Class<?> caller, final Object file) { + public static void startLoading(final Class<?> caller, final Object file) { log(caller, Resources.forLocale(null).getLogRecord(Level.FINE, Resources.Keys.LoadingDatumShiftFile_1, file)); } /** * Logs the given record. + * The logger will be {@code "org.apache.sis.referencing.operation"} and the originating + * method will be {@code "createMathTransform"} in the specified {@code caller} class. * * @param caller the provider to logs as the source class. - * the source method will be set to {@code "createMathTransform"}. * @param record the record to complete and log. */ - static void log(final Class<?> caller, final LogRecord record) { + protected static void log(final Class<?> caller, final LogRecord record) { Logging.completeAndLog(AbstractProvider.LOGGER, caller, "createMathTransform", record); } @@ -225,7 +230,7 @@ abstract class DatumShiftGridLoader { * @param file the grid file that the subclass tried to load. * @param cause the cause of the failure to load the grid file. */ - static FactoryException canNotLoad(final String format, final URI file, final Exception cause) { + public static FactoryException canNotLoad(final String format, final URI file, final Exception cause) { if (!datumDirectoryLogged.get()) { final Path directory = DataDirectory.DATUM_CHANGES.getDirectory(); if (directory != null && !datumDirectoryLogged.getAndSet(true)) { diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/NADCON.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/NADCON.java index 00849852d6..242c09f927 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/NADCON.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/NADCON.java @@ -169,7 +169,7 @@ public final class NADCON extends AbstractProvider { // Note: buffer size must be divisible by the size of `float` data type. final ByteBuffer buffer = ByteBuffer.allocate(4096).order(ByteOrder.LITTLE_ENDIAN); final FloatBuffer fb = buffer.asFloatBuffer(); - try (ReadableByteChannel in = Loader.newByteChannel(rlat)) { + try (ReadableByteChannel in = DatumShiftGridLoader.newByteChannel(rlat)) { DatumShiftGridLoader.startLoading(NADCON.class, CharSequences.commonPrefix( latitudeShifts.toString(), longitudeShifts.toString()).toString() + '…'); loader = new Loader(in, buffer, file); @@ -177,7 +177,7 @@ public final class NADCON extends AbstractProvider { } buffer.clear(); file = longitudeShifts; - try (ReadableByteChannel in = Loader.newByteChannel(rlon)) { + try (ReadableByteChannel in = DatumShiftGridLoader.newByteChannel(rlon)) { new Loader(in, buffer, file).readGrid(fb, loader, null); } } catch (IOException | NoninvertibleTransformException | RuntimeException e) { diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/NTv2.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/NTv2.java index cc93bc84ae..aa3d3412a1 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/NTv2.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/provider/NTv2.java @@ -169,7 +169,7 @@ public final class NTv2 extends AbstractProvider { final URI resolved = Loader.toAbsolutePath(file); return DatumShiftGridFile.getOrLoad(resolved, null, () -> { final DatumShiftGridFile<?,?> grid; - try (ReadableByteChannel in = Loader.newByteChannel(resolved)) { + try (ReadableByteChannel in = DatumShiftGridLoader.newByteChannel(resolved)) { DatumShiftGridLoader.startLoading(provider, file); final Loader loader = new Loader(in, file, version); grid = loader.readAllGrids();