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 Object
The stream or channel, ornull
if it has already been returned.Fields inherited from class org.apache.sis.internal.storage.io.ChannelFactory
suggestDirectBuffer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canOpen()
Returns whetherreadable(…)
orwritable(…)
can be invoked.inputStream
(String filename, StoreListeners listeners) Returns the storage object as an input stream.boolean
Returnstrue
since 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, ornull
if it has already been returned. Shall be an instance ofInputStream
,OutputStream
,ReadableByteChannel
orWritableByteChannel
.
-
-
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()Returnstrue
since use of channels or streams will affect the original storage object.- Overrides:
isCoupled
in classChannelFactory
- Returns:
- whether using the streams or channels will affect the original
storage
object.
-
canOpen
public boolean canOpen()Returns whetherreadable(…)
orwritable(…)
can be invoked.- Overrides:
canOpen
in 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 theReadableByteChannel
otherwise. The input stream can be returned at most once, otherwise an exception is thrown.- Overrides:
inputStream
in classChannelFactory
- Parameters:
filename
- data store name to report in case of failure.listeners
- set of registeredStoreListener
s for the data store, ornull
if 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 theWritableByteChannel
otherwise. The output stream can be returned at most once, otherwise an exception is thrown.- Overrides:
outputStream
in classChannelFactory
- Parameters:
filename
- data store name to report in case of failure.listeners
- set of registeredStoreListener
s for the data store, ornull
if 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:
readable
in classChannelFactory
- Parameters:
filename
- data store name to report in case of failure.listeners
- set of registeredStoreListener
s for the data store, ornull
if 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:
writable
in classChannelFactory
- Parameters:
filename
- data store name to report in case of failure.listeners
- set of registeredStoreListener
s for the data store, ornull
if 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.
-