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 6ff4ff2fa9ffbf68ba53ff7568dc2f3bad424937 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sat Dec 28 11:45:03 2024 +0100 Add a `GeoTiffStoreProvider.open(ParameterValueGroup)` method for taking in account the compression and modifiers parameters. --- .../sis/storage/geotiff/GeoTiffStoreProvider.java | 57 ++++++++++++++++++---- .../org/apache/sis/storage/DataStoreProvider.java | 22 ++++----- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java index 5d707ba4bc..0d8a63650c 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStoreProvider.java @@ -19,6 +19,8 @@ package org.apache.sis.storage.geotiff; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.logging.Logger; +import org.opengis.parameter.ParameterValueGroup; +import org.opengis.parameter.ParameterDescriptor; import org.opengis.parameter.ParameterDescriptorGroup; import org.apache.sis.util.Version; import org.apache.sis.storage.Aggregate; @@ -34,11 +36,12 @@ import org.apache.sis.storage.base.URIDataStoreProvider; import org.apache.sis.util.privy.Constants; import org.apache.sis.util.resources.Vocabulary; import org.apache.sis.parameter.ParameterBuilder; +import org.apache.sis.parameter.Parameters; /** - * The provider of {@link GeoTiffStore} instances. Given a {@link StorageConnector} input, - * this class tries to instantiate a {@code GeoTiffStore}. + * The provider of {@code GeoTiffStore} instances. + * Given a {@link StorageConnector} input, this class tries to instantiate a {@link GeoTiffStore}. * * @author Martin Desruisseaux (Geomatys) * @version 1.5 @@ -79,15 +82,25 @@ public class GeoTiffStoreProvider extends DataStoreProvider { */ static final String COMPRESSION = "compression"; + /** + * The parameter descriptor for {@link #MODIFIERS}. + */ + private static final ParameterDescriptor<FormatModifier[]> MODIFIERS_PARAM; + + /** + * The parameter descriptor for {@link #COMPRESSION}. + */ + private static final ParameterDescriptor<Compression> COMPRESSION_PARAM; + /** * The parameter descriptor to be returned by {@link #getOpenParameters()}. */ private static final ParameterDescriptorGroup OPEN_DESCRIPTOR; static { - final var builder = new ParameterBuilder(); - final var modifiers = builder.addName(MODIFIERS).setDescription(Vocabulary.formatInternational(Vocabulary.Keys.Options)).create(FormatModifier[].class, null); - final var compression = builder.addName(COMPRESSION).setDescription(Vocabulary.formatInternational(Vocabulary.Keys.Compression)).create(Compression.class, null); - OPEN_DESCRIPTOR = builder.addName(Constants.GEOTIFF).createGroup(URIDataStoreProvider.LOCATION_PARAM, modifiers, compression); + final var builder = new ParameterBuilder(); + MODIFIERS_PARAM = builder.addName(MODIFIERS).setDescription(Vocabulary.formatInternational(Vocabulary.Keys.Options)).create(FormatModifier[].class, null); + COMPRESSION_PARAM = builder.addName(COMPRESSION).setDescription(Vocabulary.formatInternational(Vocabulary.Keys.Compression)).create(Compression.class, null); + OPEN_DESCRIPTOR = builder.addName(Constants.GEOTIFF).createGroup(URIDataStoreProvider.LOCATION_PARAM, MODIFIERS_PARAM, COMPRESSION_PARAM); } /** @@ -119,14 +132,14 @@ public class GeoTiffStoreProvider extends DataStoreProvider { } /** - * Returns the MIME type if the given storage appears to be supported by {@link GeoTiffStore}. + * Returns the MIME type if the given storage appears to be supported by {@code GeoTiffStore}. * A {@linkplain ProbeResult#isSupported() supported} status does not guarantee that reading * or writing will succeed, only that there appears to be a reasonable chance of success * based on a brief inspection of the file header. * * @param connector information about the storage (URL, stream, <i>etc</i>). * @return a {@linkplain ProbeResult#isSupported() supported} status with the MIME type - * if the given storage seems to be readable by {@code GeoTiffStore} instances. + * if the given storage seems to be readable by {@link GeoTiffStore} instances. * @throws DataStoreException if an I/O error occurred. */ @Override @@ -150,10 +163,10 @@ public class GeoTiffStoreProvider extends DataStoreProvider { } /** - * Creates a {@link GeoTiffStore} implementation associated with this provider. + * Creates a {@code GeoTiffStore} instance associated with this provider. * * @param connector information about the storage (URL, stream, <i>etc</i>). - * @return a data store implementation associated with this provider for the given storage. + * @return a data store instance associated with this provider for the given storage. * @throws DataStoreException if an error occurred while creating the data store instance. */ @Override @@ -164,6 +177,30 @@ public class GeoTiffStoreProvider extends DataStoreProvider { return new GeoTiffStore(this, connector); } + /** + * Creates a {@code GeoTiffStore} instance from the given parameters. + * + * @param parameters opening parameters as defined by {@link #getOpenParameters()}. + * @return a data store instance associated with this provider for the given parameters. + * @throws DataStoreException if an error occurred while creating the data store instance. + * + * @since 1.5 + */ + @Override + public DataStore open(final ParameterValueGroup parameters) throws DataStoreException { + final var p = Parameters.castOrWrap(parameters); + final var connector = new StorageConnector(p.getValue(URIDataStoreProvider.LOCATION_PARAM)); + final FormatModifier[] modifiers = p.getValue(MODIFIERS_PARAM); + if (modifiers != null) { + connector.setOption(FormatModifier.OPTION_KEY, modifiers); + } + final Compression compression = p.getValue(COMPRESSION_PARAM); + if (compression != null) { + connector.setOption(Compression.OPTION_KEY, compression); + } + return open(connector); + } + /** * Returns the logger used by GeoTIFF stores. */ diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/DataStoreProvider.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/DataStoreProvider.java index 49503157e6..c0baf80e12 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/DataStoreProvider.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/DataStoreProvider.java @@ -20,7 +20,6 @@ import java.io.Reader; import java.io.InputStream; import java.nio.ByteBuffer; import javax.imageio.stream.ImageInputStream; -import java.util.Objects; import java.util.logging.Logger; import org.opengis.parameter.ParameterValueGroup; import org.opengis.parameter.ParameterDescriptorGroup; @@ -408,7 +407,7 @@ public abstract class DataStoreProvider { * with its own mark and position. Byte order of the view is intentionally fixed to BIG_ENDIAN * (the default) regardless the byte order of the original buffer. */ - final ByteBuffer buffer = (ByteBuffer) input; + final var buffer = (ByteBuffer) input; result = prober.test(type.cast(buffer.asReadOnlyBuffer())); } else if (input instanceof Markable) { /* @@ -416,7 +415,7 @@ public abstract class DataStoreProvider { * their own marks. In principle a single call to `reset()` is enough, but we check the * position in case the user has done some marks without resets. */ - final Markable stream = (Markable) input; + final var stream = (Markable) input; final long position = stream.getStreamPosition(); stream.mark(); result = prober.test(input); @@ -426,7 +425,7 @@ public abstract class DataStoreProvider { * `ImageInputStream` supports an arbitrary number of marks as well, * but we use absolute positioning for simplicity. */ - final ImageInputStream stream = (ImageInputStream) input; + final var stream = (ImageInputStream) input; final long position = stream.getStreamPosition(); result = prober.test(input); stream.seek(position); @@ -435,7 +434,7 @@ public abstract class DataStoreProvider { * `InputStream` supports at most one mark. So we keep it for ourselves * and wrap the stream in an object that prevent users from using marks. */ - final ProbeInputStream stream = new ProbeInputStream(connector, (InputStream) input); + final var stream = new ProbeInputStream(connector, (InputStream) input); result = prober.test(type.cast(stream)); stream.close(); // No "try with resource". See `ProbeInputStream.close()` contract. } else if (input instanceof RewindableLineReader) { @@ -449,7 +448,7 @@ public abstract class DataStoreProvider { result = prober.test(input); r.protectedReset(); } else if (input instanceof Reader) { - final ProbeReader stream = new ProbeReader(connector, (Reader) input); + final var stream = new ProbeReader(connector, (Reader) input); result = prober.test(type.cast(stream)); stream.close(); // No "try with resource". See `ProbeReader.close()` contract. } else { @@ -562,7 +561,7 @@ public abstract class DataStoreProvider { } /** - * Returns a data store implementation associated with this provider. + * Creates a data store instance associated with this provider. * This method is typically invoked when the format is not known in advance * (the {@link #probeContent(StorageConnector)} method can be tested on many providers) * or when the input is not a type accepted by {@link #open(ParameterValueGroup)} @@ -573,7 +572,7 @@ public abstract class DataStoreProvider { * creation, keeping open only the needed resource. * * @param connector information about the storage (URL, stream, JDBC connection, <i>etc</i>). - * @return a data store implementation associated with this provider for the given storage. + * @return a data store instance associated with this provider for the given storage. * @throws DataStoreException if an error occurred while creating the data store instance. * * @see DataStores#open(Object) @@ -581,7 +580,7 @@ public abstract class DataStoreProvider { public abstract DataStore open(StorageConnector connector) throws DataStoreException; /** - * Returns a data store implementation associated with this provider for the given parameters. + * Creates a data store instance associated with this provider for the given parameters. * The {@code DataStoreProvider} instance needs to be known before parameters are initialized, * since the parameters are implementation-dependent. Example: * @@ -601,7 +600,7 @@ public abstract class DataStoreProvider { * which is then passed to {@link #open(StorageConnector)}. * * @param parameters opening parameters as defined by {@link #getOpenParameters()}. - * @return a data store implementation associated with this provider for the given parameters. + * @return a data store instance associated with this provider for the given parameters. * @throws DataStoreException if an error occurred while creating the data store instance. * * @see #LOCATION @@ -611,7 +610,8 @@ public abstract class DataStoreProvider { * @since 0.8 */ public DataStore open(final ParameterValueGroup parameters) throws DataStoreException { - return open(URIDataStoreProvider.connector(this, Objects.requireNonNull(parameters))); + // IllegalOpenParameterException thrown if `parameters` is null. + return open(URIDataStoreProvider.connector(this, parameters)); } /**