Class ChannelFactory.Stream

java.lang.Object
org.apache.sis.internal.storage.io.ChannelFactory
org.apache.sis.internal.storage.io.ChannelFactory.Stream
Enclosing class:
ChannelFactory

private static final class ChannelFactory.Stream extends 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 Details

  • 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()
      Returns true since use of channels or streams will affect the original storage object.
      Overrides:
      isCoupled in class ChannelFactory
      Returns:
      whether using the streams or channels will affect the original storage object.
    • canOpen

      public boolean canOpen()
      Returns whether readable(…) or writable(…) can be invoked.
      Overrides:
      canOpen in class ChannelFactory
      Returns:
      whether readable(…) or writable(…) 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 the ReadableByteChannel otherwise. The input stream can be returned at most once, otherwise an exception is thrown.
      Overrides:
      inputStream in class ChannelFactory
      Parameters:
      filename - data store name to report in case of failure.
      listeners - set of registered StoreListeners for the data store, or null 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 the WritableByteChannel otherwise. The output stream can be returned at most once, otherwise an exception is thrown.
      Overrides:
      outputStream in class ChannelFactory
      Parameters:
      filename - data store name to report in case of failure.
      listeners - set of registered StoreListeners for the data store, or null 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 the InputStream.
      Specified by:
      readable in class ChannelFactory
      Parameters:
      filename - data store name to report in case of failure.
      listeners - set of registered StoreListeners for the data store, or null 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 the OutputStream.
      Specified by:
      writable in class ChannelFactory
      Parameters:
      filename - data store name to report in case of failure.
      listeners - set of registered StoreListeners for the data store, or null 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.