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 ca02662a4e873bf6000ff8e05e69605ee857c846 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sat Apr 16 14:26:16 2022 +0200 Be more specific about the types of accepted inputs/outputs and about the formats for which we have an entry in the `SpatialMetadata` database. --- .../sis/internal/storage/image/FormatFilter.java | 21 +++++++-------- .../apache/sis/internal/storage/image/Store.java | 30 ++++++++++++++-------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/FormatFilter.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/FormatFilter.java index 610c34eed0..3645b98c6b 100644 --- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/FormatFilter.java +++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/FormatFilter.java @@ -41,7 +41,6 @@ import javax.imageio.stream.ImageOutputStream; import org.apache.sis.storage.StorageConnector; import org.apache.sis.storage.DataStoreException; import org.apache.sis.util.ArraysExt; -import org.apache.sis.util.Classes; /** @@ -76,19 +75,21 @@ enum FormatFilter { private final Function<ImageReaderWriterSpi, String[]> property; /** - * Valid types of inputs accepted by this class. + * Types of image inputs that are accepted by {@link StorageConnector}. An input type is accepted if + * it is equal to one of those types. We do not use {@link Class#isAssignableFrom(Class)} because if + * an image reader requests a sub-type, we can probably not provide it ourselves. */ private static final Class<?>[] VALID_INPUTS = { - // ImageInputStream case included by DataInput. - DataInput.class, InputStream.class, File.class, Path.class, URL.class, URI.class + ImageInputStream.class, DataInput.class, InputStream.class, File.class, Path.class, URL.class, URI.class }; /** - * Valid types of outputs accepted by this class. + * Types of image outputs that are accepted by {@link StorageConnector}. An output type is accepted + * if it is equal to one of those types. We do not use {@link Class#isAssignableFrom(Class)} because + * if an image reader requests a sub-type, we can probably not provide it ourselves. */ private static final Class<?>[] VALID_OUTPUTS = { - // ImageOutputStream case included by DataOutput. - DataOutput.class, OutputStream.class, File.class, Path.class, URL.class, URI.class + ImageOutputStream.class, DataOutput.class, OutputStream.class, File.class, Path.class, URL.class, URI.class }; /** @@ -138,7 +139,7 @@ enum FormatFilter { final ImageReaderSpi provider = it.next(); if (done.add(provider)) { for (final Class<?> type : provider.getInputTypes()) { - if (Classes.isAssignableToAny(type, VALID_INPUTS)) { + if (ArraysExt.contains(VALID_INPUTS, type)) { final Object input = connector.getStorageAs(type); if (input != null) { /* @@ -179,7 +180,7 @@ enum FormatFilter { final ImageReaderSpi provider = it.next(); if (deferred.putIfAbsent(provider, Boolean.FALSE) == null) { for (final Class<?> type : provider.getInputTypes()) { - if (Classes.isAssignableToAny(type, VALID_INPUTS)) { + if (ArraysExt.contains(VALID_INPUTS, type)) { final Object input = connector.getStorageAs(type); if (input != null) { if (provider.canDecodeInput(input)) { @@ -222,7 +223,7 @@ enum FormatFilter { if (deferred.putIfAbsent(provider, Boolean.FALSE) == null) { if (provider.canEncodeImage(image)) { for (final Class<?> type : provider.getOutputTypes()) { - if (Classes.isAssignableToAny(type, VALID_OUTPUTS)) { + if (ArraysExt.contains(VALID_OUTPUTS, type)) { final Object output = connector.getStorageAs(type); if (output != null) { connector.closeAllExcept(output); diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java index 1a5510b1fc..a19b90927b 100644 --- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java +++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java @@ -37,9 +37,9 @@ import org.opengis.metadata.maintenance.ScopeCode; import org.opengis.referencing.datum.PixelInCell; import org.apache.sis.coverage.grid.GridExtent; import org.apache.sis.coverage.grid.GridGeometry; -import org.apache.sis.storage.Resource; import org.apache.sis.storage.Aggregate; import org.apache.sis.storage.StorageConnector; +import org.apache.sis.storage.GridCoverageResource; import org.apache.sis.storage.DataStoreException; import org.apache.sis.storage.DataStoreClosedException; import org.apache.sis.storage.DataStoreContentException; @@ -68,6 +68,13 @@ import org.apache.sis.setup.OptionKey; * @module */ final class Store extends PRJDataStore implements Aggregate { + /** + * Image I/O format names (ignoring case) for which we have an entry in the {@code SpatialMetadata} database. + */ + private static final String[] KNOWN_FORMATS = { + "PNG" + }; + /** * Index of the main image. This is relevant only with formats capable to store an arbitrary amount of images. * Current implementation assumes that the main image is always the first one, but it may become configurable @@ -343,15 +350,18 @@ loop: for (int convention=0;; convention++) { if (metadata == null) try { final MetadataBuilder builder = new MetadataBuilder(); String format = reader().getFormatName(); - if (format.equalsIgnoreCase("tif")) { - format = "TIFF"; - } - try { - builder.setPredefinedFormat(format); - } catch (MetadataStoreException e) { - builder.addFormatName(format); - listeners.warning(Level.FINE, null, e); + for (final String key : KNOWN_FORMATS) { + if (key.equalsIgnoreCase(format)) { + try { + builder.setPredefinedFormat(key); + format = null; + } catch (MetadataStoreException e) { + listeners.warning(Level.FINE, null, e); + } + break; + } } + builder.addFormatName(format); // Does nothing if `format` is null. builder.addResourceScope(ScopeCode.COVERAGE, null); builder.addSpatialRepresentation(null, getGridGeometry(MAIN_IMAGE), true); addTitleOrIdentifier(builder); @@ -368,7 +378,7 @@ loop: for (int convention=0;; convention++) { */ @Override @SuppressWarnings("ReturnOfCollectionOrArrayField") - public final synchronized Collection<? extends Resource> components() throws DataStoreException { + public final synchronized Collection<? extends GridCoverageResource> components() throws DataStoreException { if (components == null) try { components = new Components(); } catch (IOException e) {