java.lang.Object
org.apache.sis.storage.DataStore
org.apache.sis.internal.storage.folder.Store
All Implemented Interfaces:
AutoCloseable, DirectoryStream.Filter<Path>, UnstructuredAggregate, StoreResource, Aggregate, Resource, Localized
Direct Known Subclasses:
WritableStore

A folder store acts as an aggregate of multiple files in a single store. Only visible files are considered; all hidden files are excluded. Each visible file will be tested and eventually opened by another store. This approach allows to discover the content of a folder or archive without testing each file one by one.

Limitations

  • Current version is read-only.
  • Current version does not watch for external modifications in directory content.
  • Current version open all files in the directory and keep those files open. If the directory is large, it will be a problem.
  • We could open data stores concurrently. This is not yet done.
Since:
0.8
Version:
1.3
  • Field Details

    • originator

      private final Store originator
      The data store for the root directory specified by the user. May be this if this store instance is for the root directory.
    • location

      protected final Path location
      The DataStoreProvider.LOCATION parameter value.
    • identifier

      private org.opengis.util.GenericName identifier
      An identifier for this folder, or null if not yet created. Only the root folder specified by user has an initially null identifier. All sub-folders shall have a non-null identifier determined at construction time.
      See Also:
    • locale

      protected final Locale locale
      Formatting conventions of dates and numbers, or null if unspecified.
    • timezone

      protected final TimeZone timezone
      Timezone of dates in the data store, or null if unspecified.
    • encoding

      protected final Charset encoding
      Character encoding used by the data store, or null if unspecified.
    • children

      final Map<Path,DataStore> children
      All data stores (including sub-folders) found in the directory structure, including the root directory. This is used for avoiding never-ending loop with symbolic links.
    • metadata

      private transient org.opengis.metadata.Metadata metadata
      Information about the data store as a whole, created when first needed.
      See Also:
    • components

      transient Collection<Resource> components
      Resources in the folder given at construction time, created when first needed.
      See Also:
    • componentProvider

      protected final DataStoreProvider componentProvider
      The provider to use for probing the directory content, opening files and creating new files. The provider is determined by the format name specified at construction time. This field is null if that format name is null.
    • sharedRepositoryReported

      private transient boolean sharedRepositoryReported
      true if sharedRepository(Path) has already been invoked for location path. This is used for avoiding to report the same message many times.
    • structuredView

      private transient Resource structuredView
      A structured view of this aggregate, or null if not net computed. May be this if CoverageAggregator cannot do better than current resource.
      See Also:
  • Constructor Details

    • Store

      Store(DataStoreProvider provider, StorageConnector connector, Path path, DataStoreProvider format) throws DataStoreException, IOException
      Creates a new folder store from the given file, path or URI. The folder store will attempt to open only the files of the given format, if non-null. If a null format is specified, then the folder store will attempt to open any file found in the directory (this may produce confusing results).
      Parameters:
      provider - the factory that created this DataStore instance, or null if unspecified.
      connector - information about the storage (URL, stream, etc).
      path - the value of connector.getStorageAs(Path.class).
      format - format to use for reading or writing the directory content, or null.
      Throws:
      UnsupportedStorageException - if the given format name is unknown.
      DataStoreException - if an error occurred while fetching the directory Path.
      IOException - if an error occurred while using the directory Path.
    • Store

      private Store(Store parent, StorageConnector connector, org.opengis.util.NameFactory nameFactory) throws DataStoreException
      Creates a new sub-folder store as a child of the given folder store.
      Parameters:
      parent - the parent folder store.
      connector - information about the storage (URL, stream, etc).
      Throws:
      DataStoreException - if an error occurred while opening the stream.
  • Method Details

    • getOriginator

      public DataStore getOriginator()
      Returns the data store for the root directory specified by the user.
      Specified by:
      getOriginator in interface StoreResource
      Returns:
      the data store that created this resource.
    • getOpenParameters

      public Optional<org.opengis.parameter.ParameterValueGroup> getOpenParameters()
      Returns the parameters used to open this data store.
      Specified by:
      getOpenParameters in class DataStore
      Returns:
      parameters used for opening this DataStore.
      See Also:
    • accept

      public boolean accept(Path entry) throws IOException
      Invoked during iteration for omitting hidden files.
      Specified by:
      accept in interface DirectoryStream.Filter<Path>
      Throws:
      IOException
    • getIdentifier

      public Optional<org.opengis.util.GenericName> getIdentifier()
      Returns the name of this folder.
      Specified by:
      getIdentifier in interface Resource
      Overrides:
      getIdentifier in class DataStore
      Returns:
      an identifier for the root resource of this data store.
      See Also:
    • identifier

      private org.opengis.util.GenericName identifier(org.opengis.util.NameFactory nameFactory)
      Returns the name of this folder, creating it if needed. Only the root folder may have its creation delayed.
      Parameters:
      nameFactory - the factory to use for creating the root folder, or null for the default.
    • getMetadata

      public org.opengis.metadata.Metadata getMetadata()
      Returns information about the data store as a whole. Those metadata contains the directory name in the resource title.
      Specified by:
      getMetadata in interface Resource
      Specified by:
      getMetadata in class DataStore
      Returns:
      information about resources in the data store.
      See Also:
    • components

      public Collection<Resource> components() throws DataStoreException
      Returns all resources found in the folder given at construction time. Only the resources recognized by a DataStore will be included. Sub-folders are represented by other folder Store instances; their resources are available by invoking Aggregate.components() on them (this method does not traverse sub-folders recursively by itself). Resources are in no particular order.
      Specified by:
      components in interface Aggregate
      Returns:
      all children resources that are components of this aggregate. Never null.
      Throws:
      DataStoreException - if an error occurred while fetching the components.
    • canNotRead

      private String canNotRead()
      Builds an error message for an error occurring while reading files in the directory.
    • sharedRepository

      private void sharedRepository(Path candidate)
      Logs a warning about a file that could be read, but happen to be a directory that we have read previously. We could add the existing Aggregate instance in the parent Aggregate that we are building, but doing so may create a cycle. Current version logs a warning instead because users may not be prepared to handle cycles. Note that we have no guarantee that a cycle really exists at this stage, only that it may exist.
    • getStructuredView

      public Resource getStructuredView() throws DataStoreException
      Returns a more structured (if possible) view of this resource.
      Specified by:
      getStructuredView in interface UnstructuredAggregate
      Returns:
      structured view. May be this if this method cannot do better than current resource.
      Throws:
      DataStoreException - if an error occurred during the attempt to create a structured view.
    • messages

      final Resources messages()
      Returns the resource bundle to use for error message in exceptions.
    • message

      final String message(short key, Object value)
      Returns a localized string for the given key and value.
      Parameters:
      key - one of the Resources.Keys constants ending with _1 suffix.
    • close

      public void close() throws DataStoreException
      Closes all children resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in class DataStore
      Throws:
      DataStoreException - if an error occurred while closing this data store.
      See Also: