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 DataStoreProvider
The 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 Charset
Character encoding used by the data store, ornull
if unspecified.private org.opengis.util.GenericName
An identifier for this folder, ornull
if not yet created.protected final Locale
Formatting conventions of dates and numbers, ornull
if unspecified.protected final Path
TheDataStoreProvider.LOCATION
parameter value.private org.opengis.metadata.Metadata
Information about the data store as a whole, created when first needed.private final Store
The data store for the root directory specified by the user.private boolean
private Resource
A structured view of this aggregate, ornull
if not net computed.protected final TimeZone
Timezone of dates in the data store, ornull
if unspecified. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Store
(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 TypeMethodDescriptionboolean
Invoked during iteration for omitting hidden files.private String
Builds an error message for an error occurring while reading files in the directory.void
close()
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.Metadata
Returns 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.GenericName
identifier
(org.opengis.util.NameFactory nameFactory) Returns the name of this folder, creating it if needed.(package private) final String
Returns a localized string for the given key and value.(package private) final Resources
messages()
Returns the resource bundle to use for error message in exceptions.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.Methods inherited from class org.apache.sis.storage.DataStore
addListener, findResource, getDisplayName, getLocale, getNativeMetadata, getProvider, removeListener, setLocale, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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 bethis
if this store instance is for the root directory. -
location
TheDataStoreProvider.LOCATION
parameter value. -
identifier
private org.opengis.util.GenericName identifierAn identifier for this folder, ornull
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
Formatting conventions of dates and numbers, ornull
if unspecified. -
timezone
Timezone of dates in the data store, ornull
if unspecified. -
encoding
Character encoding used by the data store, ornull
if 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 isnull
if that format name is null. -
structuredView
A structured view of this aggregate, ornull
if not net computed. May bethis
ifCoverageAggregator
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 thisDataStore
instance, ornull
if 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:
getOriginator
in interfaceStoreResource
- Returns:
- the data store that created this resource.
-
getOpenParameters
Returns the parameters used to open this data store.- Specified by:
getOpenParameters
in classDataStore
- Returns:
- parameters used for opening this
DataStore
. - See Also:
-
accept
Invoked during iteration for omitting hidden files.- Specified by:
accept
in interfaceDirectoryStream.Filter<Path>
- Throws:
IOException
-
getIdentifier
Returns the name of this folder.- Specified by:
getIdentifier
in interfaceResource
- Overrides:
getIdentifier
in 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, ornull
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 interfaceResource
- Specified by:
getMetadata
in 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 aDataStore
will be included. Sub-folders are represented by other folderStore
instances; 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:
components
in 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:
getStructuredView
in interfaceUnstructuredAggregate
- 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
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.Keys
constants ending with_1
suffix.
-
close
Closes all children resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in classDataStore
- Throws:
DataStoreException
- if an error occurred while closing this data store.- See Also:
-