Class ChannelFactory.Stream
java.lang.Object
org.apache.sis.internal.storage.io.ChannelFactory
org.apache.sis.internal.storage.io.ChannelFactory.Stream
- Enclosing class:
- ChannelFactory
A factory that returns an existing channel as-is. The channel is often wrapping an
InputStream or OutputStream (which is the reason for Stream class name),
otherwise StorageConnector would hare returned the storage object
directly instead of instantiating this factory.
The channel can be returned only once.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ObjectThe stream or channel, ornullif it has already been returned.Fields inherited from class org.apache.sis.internal.storage.io.ChannelFactory
suggestDirectBuffer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanOpen()Returns whetherreadable(…)orwritable(…)can be invoked.inputStream(String filename, StoreListeners listeners) Returns the storage object as an input stream.booleanReturnstruesince use of channels or streams will affect the original storage object.outputStream(String filename, StoreListeners listeners) Returns the storage object as an output stream.readable(String filename, StoreListeners listeners) Returns the readable channel on the first invocation or throws an exception on all subsequent invocations.writable(String filename, StoreListeners listeners) Returns the writable channel on the first invocation or throws an exception on all subsequent invocations.Methods inherited from class org.apache.sis.internal.storage.io.ChannelFactory
prepare
-
Field Details
-
storage
The stream or channel, ornullif it has already been returned. Shall be an instance ofInputStream,OutputStream,ReadableByteChannelorWritableByteChannel.
-
-
Constructor Details
-
Stream
Stream(Object storage, boolean suggestDirectBuffer) Creates a new factory for the given stream or channel, which will be returned only once.
-
-
Method Details
-
isCoupled
public boolean isCoupled()Returnstruesince use of channels or streams will affect the original storage object.- Overrides:
isCoupledin classChannelFactory- Returns:
- whether using the streams or channels will affect the original
storageobject.
-
canOpen
public boolean canOpen()Returns whetherreadable(…)orwritable(…)can be invoked.- Overrides:
canOpenin classChannelFactory- Returns:
- whether
readable(…)orwritable(…)can be invoked.
-
inputStream
public InputStream inputStream(String filename, StoreListeners listeners) throws DataStoreException, IOException Returns the storage object as an input stream. This is either the stream specified at construction time if it can be returned directly, or a wrapper around theReadableByteChannelotherwise. The input stream can be returned at most once, otherwise an exception is thrown.- Overrides:
inputStreamin classChannelFactory- Parameters:
filename- data store name to report in case of failure.listeners- set of registeredStoreListeners for the data store, ornullif none.- Returns:
- the input stream.
- Throws:
DataStoreException- if the channel is read-once.IOException- if the input stream or its underlying byte channel cannot be created.
-
outputStream
public OutputStream outputStream(String filename, StoreListeners listeners) throws DataStoreException, IOException Returns the storage object as an output stream. This is either the stream specified at construction time if it can be returned directly, or a wrapper around theWritableByteChannelotherwise. The output stream can be returned at most once, otherwise an exception is thrown.- Overrides:
outputStreamin classChannelFactory- Parameters:
filename- data store name to report in case of failure.listeners- set of registeredStoreListeners for the data store, ornullif none.- Returns:
- the output stream.
- Throws:
DataStoreException- if the channel is write-once.IOException- if the output stream or its underlying byte channel cannot be created.
-
readable
public ReadableByteChannel readable(String filename, StoreListeners listeners) throws DataStoreException, IOException Returns the readable channel on the first invocation or throws an exception on all subsequent invocations. This is either the channel specified at construction time, or a wrapper around theInputStream.- Specified by:
readablein classChannelFactory- Parameters:
filename- data store name to report in case of failure.listeners- set of registeredStoreListeners for the data store, ornullif none.- Returns:
- the channel for the given input.
- Throws:
DataStoreException- if the channel is read-once.IOException- if an error occurred while opening the channel.
-
writable
public WritableByteChannel writable(String filename, StoreListeners listeners) throws DataStoreException, IOException Returns the writable channel on the first invocation or throws an exception on all subsequent invocations. This is either the channel specified at construction time, or a wrapper around theOutputStream.- Specified by:
writablein classChannelFactory- Parameters:
filename- data store name to report in case of failure.listeners- set of registeredStoreListeners for the data store, ornullif none.- Returns:
- the channel for the given output.
- Throws:
DataStoreException- if the channel is write-once.IOException- if an error occurred while opening the channel.
-