public abstract class DataStoreProvider extends Object
DataStore
instances for a specific format from a given StorageConnector
input.
There is typically a different DataStoreProvider
instance for each format provided by a library.Defined in the sis-storage module
Modifier | Constructor and Description |
---|---|
protected |
DataStoreProvider()
Creates a new provider.
|
Modifier and Type | Method and Description |
---|---|
abstract Boolean |
canOpen(StorageConnector storage)
Returns
TRUE if the given storage appears to be supported by the DataStore . |
abstract DataStore |
open(StorageConnector storage)
Returns a data store implementation associated with this provider.
|
public abstract Boolean canOpen(StorageConnector storage) throws DataStoreException
TRUE
if the given storage appears to be supported by the DataStore
.
Returning TRUE
from this method does not guarantee that reading or writing will succeed,
only that there appears to be a reasonable chance of success based on a brief inspection of the
storage object or contents.
Implementations will typically check the first bytes of the stream for a "magic number" associated with the format, as in the following example:
Implementors are responsible for restoring the input to its original stream position on return of this method. Implementors can use a mark/reset pair for this purpose. Marks are available asfinal ByteBuffer buffer = storage.getStorageAs(ByteBuffer.class); if (buffer == null) { // If StorageConnector can not provide a ByteBuffer, then the storage is probably // not a File, URL, URI, InputStream neither a ReadableChannel. In this example, // our provider can not handle such unknown source. return Boolean.FALSE; } if (buffer.remaining() < Integer.SIZE / Byte.SIZE) { // If the buffer does not contain enough bytes for the 'int' type, this is not necessarily // because the file is truncated. It may be because the data were not yet available at the // time this method has been invoked. Returning 'null' means "don't know". return null; } // Use ByteBuffer.getInt(int) instead than ByteBuffer.getInt() in order to keep buffer position // unchanged after this method call. return buffer.getInt(buffer.position()) == MAGIC_NUMBER;
Buffer.mark()
, InputStream.mark(int)
and
ImageInputStream.mark()
.
Warning: this method is likely to change. SIS 0.4 will probably return a set of enumeration values describing how the file can be open (read, write, append) similar to JDK7 open mode. |
storage
- Information about the storage (URL, stream, JDBC connection, etc).Boolean.TRUE
if the given storage seems to be usable by the DataStore
instances
create by this provider, Boolean.FALSE
if the DataStore
will not be able to use
the given storage, or null
if this method does not have enough information.DataStoreException
- if an I/O or SQL error occurred. The error shall be unrelated to the logical
structure of the storage.public abstract DataStore open(StorageConnector storage) throws DataStoreException
Implementation note:
Implementors shall invoke StorageConnector.closeAllExcept(Object)
after DataStore
creation, keeping open only the needed resource.
storage
- Information about the storage (URL, stream, JDBC connection, etc).DataStoreException
- if an error occurred while creating the data store instance.Copyright © 2010–2013 The Apache Software Foundation. All rights reserved.