Class Store
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
class Store
extends DataStore
implements StoreResource, UnstructuredAggregate, DirectoryStream.Filter<Path>
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 Summary
FieldsModifier and TypeFieldDescriptionAll data stores (including sub-folders) found in the directory structure, including the root directory.protected final DataStoreProviderThe provider to use for probing the directory content, opening files and creating new files.(package private) Collection<Resource>Resources in the folder given at construction time, created when first needed.protected final CharsetCharacter encoding used by the data store, ornullif unspecified.private org.opengis.util.GenericNameAn identifier for this folder, ornullif not yet created.protected final LocaleFormatting conventions of dates and numbers, ornullif unspecified.protected final PathTheDataStoreProvider.LOCATIONparameter value.private org.opengis.metadata.MetadataInformation about the data store as a whole, created when first needed.private final StoreThe data store for the root directory specified by the user.private booleanprivate ResourceA structured view of this aggregate, ornullif not net computed.protected final TimeZoneTimezone of dates in the data store, ornullif unspecified. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateStore(Store parent, StorageConnector connector, org.opengis.util.NameFactory nameFactory) Creates a new sub-folder store as a child of the given folder store.(package private)Store(DataStoreProvider provider, StorageConnector connector, Path path, DataStoreProvider format) Creates a new folder store from the given file, path or URI. -
Method Summary
Modifier and TypeMethodDescriptionbooleanInvoked during iteration for omitting hidden files.private StringBuilds an error message for an error occurring while reading files in the directory.voidclose()Closes all children resources.Returns all resources found in the folder given at construction time.Optional<org.opengis.util.GenericName>Returns the name of this folder.org.opengis.metadata.MetadataReturns information about the data store as a whole.Optional<org.opengis.parameter.ParameterValueGroup>Returns the parameters used to open this data store.Returns the data store for the root directory specified by the user.Returns a more structured (if possible) view of this resource.private org.opengis.util.GenericNameidentifier(org.opengis.util.NameFactory nameFactory) Returns the name of this folder, creating it if needed.(package private) final StringReturns a localized string for the given key and value.(package private) final Resourcesmessages()Returns the resource bundle to use for error message in exceptions.private voidsharedRepository(Path candidate) Logs a warning about a file that could be read, but happen to be a directory that we have read previously.Methods inherited from class org.apache.sis.storage.DataStore
addListener, findResource, getDisplayName, getLocale, getNativeMetadata, getProvider, removeListener, setLocale, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sis.storage.Resource
addListener, removeListener
-
Field Details
-
originator
The data store for the root directory specified by the user. May bethisif this store instance is for the root directory. -
location
TheDataStoreProvider.LOCATIONparameter value. -
identifier
private org.opengis.util.GenericName identifierAn identifier for this folder, ornullif 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
Formatting conventions of dates and numbers, ornullif unspecified. -
timezone
Timezone of dates in the data store, ornullif unspecified. -
encoding
Character encoding used by the data store, ornullif unspecified. -
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 metadataInformation about the data store as a whole, created when first needed.- See Also:
-
components
Resources in the folder given at construction time, created when first needed.- See Also:
-
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 isnullif that format name is null. -
structuredView
A structured view of this aggregate, ornullif not net computed. May bethisifCoverageAggregatorcannot 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 thisDataStoreinstance, ornullif unspecified.connector- information about the storage (URL, stream, etc).path- the value ofconnector.getStorageAs(Path.class).format- format to use for reading or writing the directory content, ornull.- Throws:
UnsupportedStorageException- if the given format name is unknown.DataStoreException- if an error occurred while fetching the directoryPath.IOException- if an error occurred while using the directoryPath.
-
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
Returns the data store for the root directory specified by the user.- Specified by:
getOriginatorin interfaceStoreResource- Returns:
- the data store that created this resource.
-
getOpenParameters
Returns the parameters used to open this data store.- Specified by:
getOpenParametersin classDataStore- Returns:
- parameters used for opening this
DataStore. - See Also:
-
accept
Invoked during iteration for omitting hidden files.- Specified by:
acceptin interfaceDirectoryStream.Filter<Path>- Throws:
IOException
-
getIdentifier
Returns the name of this folder.- Specified by:
getIdentifierin interfaceResource- Overrides:
getIdentifierin classDataStore- 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, ornullfor 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:
getMetadatain interfaceResource- Specified by:
getMetadatain classDataStore- Returns:
- information about resources in the data store.
- See Also:
-
components
Returns all resources found in the folder given at construction time. Only the resources recognized by aDataStorewill be included. Sub-folders are represented by other folderStoreinstances; their resources are available by invokingAggregate.components()on them (this method does not traverse sub-folders recursively by itself). Resources are in no particular order.- Specified by:
componentsin interfaceAggregate- Returns:
- all children resources that are components of this aggregate. Never
null. - Throws:
DataStoreException- if an error occurred while fetching the components.
-
canNotRead
Builds an error message for an error occurring while reading files in the directory. -
getStructuredView
Returns a more structured (if possible) view of this resource.- Specified by:
getStructuredViewin interfaceUnstructuredAggregate- Returns:
- structured view. May be
thisif this method cannot do better than current resource. - Throws:
DataStoreException- if an error occurred during the attempt to create a structured view.
-
messages
Returns the resource bundle to use for error message in exceptions. -
message
Returns a localized string for the given key and value.- Parameters:
key- one of theResources.Keysconstants ending with_1suffix.
-
close
Closes all children resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein classDataStore- Throws:
DataStoreException- if an error occurred while closing this data store.- See Also:
-