This is an automated email from the ASF dual-hosted git repository. jsorel 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 1bf1075fed Delay reading items in GIMI store, add javadoc 1bf1075fed is described below commit 1bf1075feda331b27932be78e317617adabd63fe Author: jsorel <johann.so...@geomatys.com> AuthorDate: Thu Oct 3 09:54:05 2024 +0200 Delay reading items in GIMI store, add javadoc --- .../org/apache/sis/storage/gimi/GimiStore.java | 125 +++++++++++------- .../apache/sis/storage/gimi/GimiTileMatrix.java | 2 +- .../org/apache/sis/storage/gimi/GimiUtils.java | 53 -------- .../gimi/{ResourceUnknown.java => Group.java} | 43 ++++--- .../main/org/apache/sis/storage/gimi/Item.java | 140 +++++++++++++++------ .../org/apache/sis/storage/gimi/ResourceGrid.java | 8 +- .../apache/sis/storage/gimi/ResourceImageJpeg.java | 1 + .../storage/gimi/ResourceImageUncompressed.java | 4 +- .../apache/sis/storage/gimi/ResourcePyramid.java | 5 +- .../apache/sis/storage/gimi/ResourceUnknown.java | 1 + .../sis/storage/gimi/isobmff/ISOBMFFReader.java | 22 ++++ 11 files changed, 244 insertions(+), 160 deletions(-) diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/GimiStore.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/GimiStore.java index f383d49897..19d6059602 100644 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/GimiStore.java +++ b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/GimiStore.java @@ -34,11 +34,13 @@ import org.apache.sis.parameter.Parameters; import org.apache.sis.storage.Aggregate; import org.apache.sis.storage.DataStore; import org.apache.sis.storage.DataStoreException; +import org.apache.sis.storage.IllegalNameException; import org.apache.sis.storage.Resource; import org.apache.sis.storage.StorageConnector; import org.apache.sis.storage.base.MetadataBuilder; import org.apache.sis.storage.gimi.isobmff.Box; import org.apache.sis.storage.gimi.isobmff.ISOBMFFReader; +import org.apache.sis.storage.gimi.isobmff.iso14496_12.EntityToGroup; import org.apache.sis.storage.gimi.isobmff.iso14496_12.GroupList; import org.apache.sis.storage.gimi.isobmff.iso14496_12.ItemInfo; import org.apache.sis.storage.gimi.isobmff.iso14496_12.ItemInfoEntry; @@ -57,6 +59,7 @@ public final class GimiStore extends DataStore implements Aggregate { private final Path gimiPath; private List<Resource> components; + private Map<Integer,Item> itemIndex; private Map<Integer,Resource> componentIndex; private Metadata metadata; @@ -88,16 +91,6 @@ public final class GimiStore extends DataStore implements Aggregate { return metadata; } - @Override - public synchronized void close() throws DataStoreException { - try { - reader.channel.channel.close(); - reader = null; - } catch (IOException ex) { - throw new DataStoreException("Fail to closed channel", ex); - } - } - synchronized ISOBMFFReader getReader() throws DataStoreException { if (reader == null) { final StorageConnector cnx = new StorageConnector(gimiPath); @@ -129,70 +122,76 @@ public final class GimiStore extends DataStore implements Aggregate { if (components != null) return components; components = new ArrayList<>(); + itemIndex = new HashMap<>(); componentIndex = new HashMap<>(); - //collect elements which should not be displayed since they are part of a larger image (grid or pyramid) + /* + * Collect elements which should not be displayed since they are part of a larger image (grid or pyramid) + */ final Set<Integer> includedInParents = new HashSet<>(); try { final Box root = getRootBox(); final Meta meta = (Meta) root.getChild(Meta.FCC, null); - - //single items + final Box groups = meta.getChild(GroupList.FCC, null); final ItemInfo iinf = (ItemInfo) meta.getChild(ItemInfo.FCC, null); + + /* + * Build item index. + * Create GridImages and collect used items. + */ for (ItemInfoEntry iie : iinf.entries) { final Item item = new Item(this, iie); - Resource resource; - if (ResourceImageUncompressed.TYPE.equals(iie.itemType)) { - //uncompressed image - resource = new ResourceImageUncompressed(this, item); - } else if (ResourceImageJpeg.TYPE.equals(iie.itemType)) { - //jpeg image - resource = new ResourceImageJpeg(this, item); - } else if (ResourceGrid.TYPE.equals(iie.itemType)) { - //tiled image - resource = new ResourceGrid(item); - - for (SingleItemTypeReference refs : item.references) { + itemIndex.put(iie.itemId, item); + + if (ResourceGrid.TYPE.equals(iie.itemType)) { + for (SingleItemTypeReference refs : item.getReferences()) { + final ResourceGrid resource = new ResourceGrid(item); + componentIndex.put(iie.itemId, resource); for (int i :refs.toItemId) { includedInParents.add(i); } } - } else { - //TODO - resource = new ResourceUnknown(this, item); } - components.add(resource); - componentIndex.put(iie.itemId, resource); } - //groups - final Box groups = meta.getChild(GroupList.FCC, null); + /* + * Read groups. + * Create pyramids and groups and collect used items. + */ if (groups != null) { for (Box b : groups.getChildren()) { if (b instanceof ImagePyramidEntityGroup) { final ImagePyramidEntityGroup img = (ImagePyramidEntityGroup) b; final ResourcePyramid pyramid = new ResourcePyramid(this, img); components.add(pyramid); - componentIndex.put(pyramid.group.groupId, pyramid); - - //force initialize now, pyramids may amend existing grids - pyramid.getGridGeometry(); for (int i :img.entitiesId) { includedInParents.add(i); } + } else if (b instanceof EntityToGroup) { + final EntityToGroup grp = (EntityToGroup) b; + final Group group = new Group(this, grp); + components.add(group); + + for (int i :grp.entitiesId) { + includedInParents.add(i); + } } } } - } catch (Exception ex) { - ex.printStackTrace(); - } + /* + * Add all items not used by groups and grids. + */ + final Set<Integer> keys = new HashSet<>(itemIndex.keySet()); + keys.removeAll(includedInParents); + for (Integer k : keys) { + components.add(getComponent(k)); + } - //remove resources which are in a parent - for (Integer itemId : includedInParents) { - components.remove(componentIndex.get(itemId)); + } catch (IOException ex) { + throw new DataStoreException(ex.getMessage(), ex); } return components; @@ -200,12 +199,48 @@ public final class GimiStore extends DataStore implements Aggregate { /** * Get file item as Resource. + * * @param itemId item identifier - * @return resource or null if not found + * @return resource current or created resource */ - Resource getComponent(int itemId) throws DataStoreException { + synchronized Resource getComponent(int itemId) throws DataStoreException { components(); - return componentIndex.get(itemId); + Resource resource = componentIndex.get(itemId); + if (resource == null) { + final Item item = itemIndex.get(itemId); + if (item == null) { + throw new IllegalNameException("No item for id : " + itemId); + } + + if (ResourceImageUncompressed.TYPE.equals(item.entry.itemType)) { + //uncompressed image + resource = new ResourceImageUncompressed(this, item); + } else if (ResourceImageJpeg.TYPE.equals(item.entry.itemType)) { + //jpeg image + resource = new ResourceImageJpeg(this, item); + } else if (ResourceGrid.TYPE.equals(item.entry.itemType)) { + //tiled image + resource = new ResourceGrid(item); + } else { + //TODO + resource = new ResourceUnknown(this, item); + } + } + componentIndex.put(itemId, resource); + return resource; } + /** + * Release internal reader. + * @throws DataStoreException if closing operation fails + */ + @Override + public synchronized void close() throws DataStoreException { + try { + reader.channel.channel.close(); + reader = null; + } catch (IOException ex) { + throw new DataStoreException("Fail to closed channel", ex); + } + } } diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/GimiTileMatrix.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/GimiTileMatrix.java index c7e09cf8fd..1f4b4ad48c 100644 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/GimiTileMatrix.java +++ b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/GimiTileMatrix.java @@ -75,7 +75,7 @@ final class GimiTileMatrix implements TileMatrix { @Override public Optional<Tile> getTile(long... indices) throws DataStoreException { final int itemIdx = Math.toIntExact(indices[0] + indices[1] * tilingScheme.getExtent().getSize(0)); - return Optional.of(new GimiTile(grid.getItem().store, indices, grid.getItem().references.get(0).toItemId[itemIdx])); + return Optional.of(new GimiTile(grid.getItem().store, indices, grid.getItem().getReferences().get(0).toItemId[itemIdx])); } @Override diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/GimiUtils.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/GimiUtils.java deleted file mode 100644 index c2b1cd3fab..0000000000 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/GimiUtils.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sis.storage.gimi; - -import java.io.EOFException; -import java.io.IOException; -import java.nio.file.Path; -import org.apache.sis.io.stream.ChannelDataInput; -import org.apache.sis.storage.DataStoreException; -import org.apache.sis.storage.StorageConnector; -import org.apache.sis.storage.gimi.isobmff.Box; -import org.apache.sis.storage.gimi.isobmff.ISOBMFFReader; - - -/** - * - * @author Johann Sorel (Geomatys) - */ -public class GimiUtils { - - public static void printAll(Path path) throws IllegalArgumentException, DataStoreException, IOException { - - final StorageConnector cnx = new StorageConnector(path); - final ChannelDataInput cdi = cnx.getStorageAs(ChannelDataInput.class); - final ISOBMFFReader reader = new ISOBMFFReader(cdi); - - try { - while(true) { - final Box box = reader.readBox(); - System.out.println(box); - cdi.seek(box.boxOffset + box.size); - - } - } catch (EOFException ex) { - //do nothing - } - } - -} diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceUnknown.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/Group.java similarity index 56% copy from incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceUnknown.java copy to incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/Group.java index 635b8673e6..1626befc54 100644 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceUnknown.java +++ b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/Group.java @@ -16,46 +16,51 @@ */ package org.apache.sis.storage.gimi; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.Optional; import org.apache.sis.storage.AbstractResource; -import org.apache.sis.storage.DataStore; +import org.apache.sis.storage.Aggregate; import org.apache.sis.storage.DataStoreException; -import org.apache.sis.storage.base.StoreResource; +import org.apache.sis.storage.Resource; +import org.apache.sis.storage.gimi.isobmff.iso14496_12.EntityToGroup; import org.apache.sis.util.iso.Names; import org.opengis.util.GenericName; - /** - * Unknown item type. + * An unidentified group of entities. * * @author Johann Sorel (Geomatys) */ -final class ResourceUnknown extends AbstractResource implements StoreResource { +public final class Group extends AbstractResource implements Aggregate { private final GimiStore store; - private final Item item; - private final GenericName identifier; + final EntityToGroup group; - public ResourceUnknown(GimiStore store, Item item) throws DataStoreException { - super(store); - this.store = store; - this.item = item; + //cache linked resources + private List<Resource> components; - if (item.entry.itemName == null || item.entry.itemName.isBlank()) { - this.identifier = Names.createLocalName(null, null, Integer.toString(item.entry.itemId)); - } else { - this.identifier = Names.createLocalName(null, null, item.entry.itemName); - } + public Group(GimiStore store, EntityToGroup group) { + super(null); + this.store = store; + this.group = group; } @Override public Optional<GenericName> getIdentifier() throws DataStoreException { - return Optional.of(identifier); + return Optional.of(Names.createLocalName(null, null, "EntityGroup " + group.groupId)); } @Override - public DataStore getOriginator() { - return store; + public synchronized Collection<? extends Resource> components() throws DataStoreException { + if (components != null) return components; + + components = new ArrayList<>(group.entitiesId.length); + for (int entityId : group.entitiesId) { + components.add(store.getComponent(entityId)); + } + return components; } } diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/Item.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/Item.java index 75100b70bb..3fd046d6cf 100644 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/Item.java +++ b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/Item.java @@ -36,70 +36,140 @@ import org.apache.sis.storage.gimi.isobmff.iso14496_12.SingleItemTypeReference; /** - * Regroup properties of a single item in the file. + * Regroup properties of a single item of the file. * * @author Johann Sorel (Geomatys) */ final class Item { + private static final ItemLocation.Item NO_LOCATION = new ItemLocation.Item(); + public final GimiStore store; public final ItemInfoEntry entry; - public final boolean isPrimary; - public final List<Box> properties = new ArrayList<>(); - public final List<SingleItemTypeReference> references = new ArrayList<>(); - public final ItemLocation.Item location; + + // caches + private List<Box> properties; + private List<SingleItemTypeReference> references; + private ItemLocation.Item location; + private Boolean isPrimary; public Item(GimiStore store, ItemInfoEntry entry) throws IllegalArgumentException, DataStoreException, IOException { this.store = store; this.entry = entry; - final Box meta = store.getRootBox().getChild(Meta.FCC, null); - //is item primary - final PrimaryItem primaryItem = (PrimaryItem) meta.getChild(PrimaryItem.FCC, null); - if (primaryItem != null) { - isPrimary = primaryItem.itemId == entry.itemId; - } else { - isPrimary = true; + } + + /** + * @return true if this item is the primary item defined in the file + */ + public synchronized boolean isPrimary() throws DataStoreException { + if (isPrimary != null) return isPrimary; + try { + final Box meta = store.getRootBox().getChild(Meta.FCC, null); + final PrimaryItem primaryItem = (PrimaryItem) meta.getChild(PrimaryItem.FCC, null); + if (primaryItem != null) { + isPrimary = primaryItem.itemId == entry.itemId; + } else { + isPrimary = true; + } + } catch (IOException ex) { + throw new DataStoreException(ex.getMessage(), ex); } + + return isPrimary; + } + + /** + * List all property boxes. + * + * @return list of property boxes, can be empty. + */ + public synchronized List<Box> getProperties() throws DataStoreException { + if (properties != null) return properties; + //extract properties - final Box itemProperties = meta.getChild(ItemProperties.FCC, null); - if (itemProperties != null) { - final ItemPropertyContainer itemPropertiesContainer = (ItemPropertyContainer) itemProperties.getChild(ItemPropertyContainer.FCC, null); - final List<Box> allProperties = itemPropertiesContainer.getChildren(); - final ItemPropertyAssociation itemPropertiesAssociations = (ItemPropertyAssociation) itemProperties.getChild(ItemPropertyAssociation.FCC, null); - for (ItemPropertyAssociation.Entry en : itemPropertiesAssociations.entries) { - if (en.itemId == entry.itemId) { - for (int i : en.propertyIndex) { - properties.add(allProperties.get(i - 1)); //starts at 1 + properties = new ArrayList<>(); + try { + final Box meta = store.getRootBox().getChild(Meta.FCC, null); + final Box itemProperties = meta.getChild(ItemProperties.FCC, null); + if (itemProperties != null) { + final ItemPropertyContainer itemPropertiesContainer = (ItemPropertyContainer) itemProperties.getChild(ItemPropertyContainer.FCC, null); + final List<Box> allProperties = itemPropertiesContainer.getChildren(); + final ItemPropertyAssociation itemPropertiesAssociations = (ItemPropertyAssociation) itemProperties.getChild(ItemPropertyAssociation.FCC, null); + for (ItemPropertyAssociation.Entry en : itemPropertiesAssociations.entries) { + if (en.itemId == entry.itemId) { + for (int i : en.propertyIndex) { + properties.add(allProperties.get(i - 1)); //starts at 1 + } + break; } - break; } } + } catch (IOException ex) { + throw new DataStoreException(ex.getMessage(), ex); } + return properties; + } + + /** + * Override property boxes. + * + * @param boxes not null + */ + synchronized void setProperties(List<Box> boxes) { + this.properties = boxes; + } + + public synchronized List<SingleItemTypeReference> getReferences() throws DataStoreException { + if (references != null) return references; + //extract outter references - final ItemReference itemReferences = (ItemReference) meta.getChild(ItemReference.FCC, null); - if (itemReferences != null) { - for (SingleItemTypeReference sitr : itemReferences.references) { - if (sitr.fromItemId == entry.itemId) { - references.add(sitr); + references = new ArrayList<>(); + try { + final Box meta = store.getRootBox().getChild(Meta.FCC, null); + final ItemReference itemReferences = (ItemReference) meta.getChild(ItemReference.FCC, null); + if (itemReferences != null) { + for (SingleItemTypeReference sitr : itemReferences.references) { + if (sitr.fromItemId == entry.itemId) { + references.add(sitr); + } } } + } catch (IOException ex) { + throw new DataStoreException(ex.getMessage(), ex); } + + return references; + } + + synchronized void setReferences(List<SingleItemTypeReference> refs) { + this.references = refs; + } + + public synchronized ItemLocation.Item getLocation() throws DataStoreException { + if (location != null) return location == NO_LOCATION ? null : location; + //extract location - ItemLocation.Item loc = null; - final ItemLocation itemLocation = (ItemLocation) meta.getChild(ItemLocation.FCC, null); - if (itemLocation != null) { - for (ItemLocation.Item en : itemLocation.items) { - if (en.itemId == entry.itemId) { - loc = en; - break; + location = NO_LOCATION; + try { + final Box meta = store.getRootBox().getChild(Meta.FCC, null); + final ItemLocation itemLocation = (ItemLocation) meta.getChild(ItemLocation.FCC, null); + if (itemLocation != null) { + for (ItemLocation.Item en : itemLocation.items) { + if (en.itemId == entry.itemId) { + location = en; + break; + } } } + } catch (IOException ex) { + throw new DataStoreException(ex.getMessage(), ex); } - this.location = loc; + return location == NO_LOCATION ? null : location; } public byte[] getData() throws DataStoreException { try { + final ItemLocation.Item location = getLocation(); if (location == null) { //read data from the default mediadata box MediaData mediaData = (MediaData) store.getRootBox().getChild(MediaData.FCC, null); diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceGrid.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceGrid.java index e617a76823..97ec9991e7 100644 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceGrid.java +++ b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceGrid.java @@ -44,12 +44,14 @@ import org.opengis.util.FactoryException; /** + * A Grid as a GridCoverageResource and as a TiledResource. * * @author Johann Sorel (Geomatys) */ final class ResourceGrid extends MatrixGridRessource implements TiledResource, StoreResource { public static final String TYPE = "grid"; + private final Item item; private final GenericName identifier; //filled after initialize @@ -72,7 +74,7 @@ final class ResourceGrid extends MatrixGridRessource implements TiledResource, S * * @return item, never null. */ - public Item getItem() { + Item getItem() { return item; } @@ -99,7 +101,7 @@ final class ResourceGrid extends MatrixGridRessource implements TiledResource, S private synchronized void initialize() throws DataStoreException { if (tileMatrix != null) return; - final Resource first = item.store.getComponent(item.references.get(0).toItemId[0]); + final Resource first = item.store.getComponent(item.getReferences().get(0).toItemId[0]); if (first instanceof GridCoverageResource) { this.first = (GridCoverageResource) first; } else { @@ -114,7 +116,7 @@ final class ResourceGrid extends MatrixGridRessource implements TiledResource, S ModelTransformationProperty modelTrs = null; WellKnownText2Property modelWkt = null; - for (Box box : item.properties) { + for (Box box : item.getProperties()) { if (box instanceof ImageSpatialExtents) { imageExts = (ImageSpatialExtents) box; } else if (box instanceof ModelTransformationProperty) { diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceImageJpeg.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceImageJpeg.java index 35892544c9..9433723778 100644 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceImageJpeg.java +++ b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceImageJpeg.java @@ -28,6 +28,7 @@ import org.apache.sis.storage.DataStoreException; /** + * A jpeg image as a GridCoverageResource. * * @author Johann Sorel (Geomatys) */ diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceImageUncompressed.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceImageUncompressed.java index bfd8883b51..cc91245c96 100644 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceImageUncompressed.java +++ b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceImageUncompressed.java @@ -50,7 +50,7 @@ import org.opengis.referencing.operation.MathTransform; /** - * A single uncompressed image. + * A single uncompressed image as a GridCoverageResource. * * @author Johann Sorel (Geomatys) */ @@ -97,7 +97,7 @@ class ResourceImageUncompressed extends AbstractGridCoverageResource implements super(store); this.store = store; this.item = item; - for (Box box : item.properties) { + for (Box box : item.getProperties()) { if (box instanceof ComponentDefinition) { compDef = (ComponentDefinition) box; } else if (box instanceof ImageSpatialExtents) { diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourcePyramid.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourcePyramid.java index 6838a5464d..85dc8d3051 100644 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourcePyramid.java +++ b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourcePyramid.java @@ -52,6 +52,7 @@ import org.opengis.referencing.operation.MathTransform; /** + * Map an ImagePyramidEntityGroup as a GridCoverageResource and as a TiledResource. * * @author Johann Sorel (Geomatys) */ @@ -97,10 +98,10 @@ final class ResourcePyramid extends AbstractGridCoverageResource implements Tile final ItemInfoEntry entry = new ItemInfoEntry(); entry.itemId = -tileItemId; //fake id, should not be used final Item item = new Item(store, entry); - item.references.add(new SingleItemTypeReference(entry.itemId, new int[]{tileItemId})); + item.setReferences(List.of(new SingleItemTypeReference(entry.itemId, new int[]{tileItemId}))); final GridExtent tileExtent = gcr.getGridGeometry().getExtent(); final ImageSpatialExtents ext = new ImageSpatialExtents(Math.toIntExact(tileExtent.getSize(0)), Math.toIntExact(tileExtent.getSize(1))); - item.properties.add(ext); + item.setProperties(List.of(ext)); res = new ResourceGrid(item); } catch (IOException ex) { throw new DataStoreException(ex); diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceUnknown.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceUnknown.java index 635b8673e6..0994f09d74 100644 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceUnknown.java +++ b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/ResourceUnknown.java @@ -27,6 +27,7 @@ import org.opengis.util.GenericName; /** * Unknown item type. + * We display those items as Resource even if we have only minimal support. * * @author Johann Sorel (Geomatys) */ diff --git a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/isobmff/ISOBMFFReader.java b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/isobmff/ISOBMFFReader.java index b279c4e54f..41a3e4fa15 100644 --- a/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/isobmff/ISOBMFFReader.java +++ b/incubator/src/org.apache.sis.storage.gimi/main/org/apache/sis/storage/gimi/isobmff/ISOBMFFReader.java @@ -16,9 +16,11 @@ */ package org.apache.sis.storage.gimi.isobmff; +import java.io.EOFException; import java.io.IOException; import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import java.util.Set; import java.util.Map; import java.util.HashMap; @@ -27,7 +29,9 @@ import java.util.Iterator; import java.util.ServiceLoader; import java.util.UUID; import org.apache.sis.io.stream.ChannelDataInput; +import org.apache.sis.storage.DataStoreException; import org.apache.sis.storage.IllegalNameException; +import org.apache.sis.storage.StorageConnector; import org.apache.sis.storage.gimi.isobmff.iso14496_12.Extension; @@ -155,4 +159,22 @@ public final class ISOBMFFReader { return str; } + + public static void printAll(Path path) throws IllegalArgumentException, DataStoreException, IOException { + + final StorageConnector cnx = new StorageConnector(path); + final ChannelDataInput cdi = cnx.getStorageAs(ChannelDataInput.class); + final ISOBMFFReader reader = new ISOBMFFReader(cdi); + + try { + while(true) { + final Box box = reader.readBox(); + System.out.println(box); + cdi.seek(box.boxOffset + box.size); + } + } catch (EOFException ex) { + //do nothing + } + } + }