Class ChannelFactory.Fallback

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

private static final class ChannelFactory.Fallback extends ChannelFactory
A factory used as a fallback when we failed to convert a File to a Path. This is used only if the conversion attempt threw an InvalidPathException. Such failure is unlikely to happen, but if it happens anyway we try to open the channel in a less surprising way for the user (i.e. closer to the object (s)he has specified).
  • Field Details

    • file

      private final File file
      The file for which to open a channel.
    • cause

      private InvalidPathException cause
      The reason why we are using this fallback instead of a Path. Will be reported at most once, then set to null.
  • Constructor Details

  • Method Details

    • inputStream

      public FileInputStream inputStream(String filename, StoreListeners listeners) throws IOException
      Opens a new input stream for the file given at construction time. The returned stream is not buffered.

      On the first invocation, this method reports a warning about the failure to convert the File to a Path. On all subsequent invocations, the file is opened silently.

      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:
      IOException - if the input stream or its underlying byte channel cannot be created.
    • outputStream

      public FileOutputStream outputStream(String filename, StoreListeners listeners) throws IOException
      Opens a new output stream for the file given at construction time. The returned stream is not buffered.

      On the first invocation, this method reports a warning about the failure to convert the File to a Path. On all subsequent invocations, the file is opened silently.

      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:
      IOException - if the output stream or its underlying byte channel cannot be created.
    • warning

      private void warning(String method, StoreListeners listeners)
      Invoked when we have been able to create a channel, but maybe not with the given OpenOptions. Since the exception was nevertheless unexpected, log its stack trace in order to allow the developer to check if there is something wrong.
    • readable

      public ReadableByteChannel readable(String filename, StoreListeners listeners) throws IOException
      Opens a new channel for the file given at construction time.
      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:
      IOException - if an error occurred while opening the channel.
    • writable

      public WritableByteChannel writable(String filename, StoreListeners listeners) throws IOException
      Opens a new channel for the file given at construction time.
      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:
      IOException - if an error occurred while opening the channel.