Class ChannelFactory.Fallback
java.lang.Object
org.apache.sis.internal.storage.io.ChannelFactory
org.apache.sis.internal.storage.io.ChannelFactory.Fallback
- Enclosing class:
- 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 Summary
FieldsModifier and TypeFieldDescriptionprivate InvalidPathExceptionThe reason why we are using this fallback instead of aPath.private final FileThe file for which to open a channel.Fields inherited from class org.apache.sis.internal.storage.io.ChannelFactory
suggestDirectBuffer -
Constructor Summary
ConstructorsConstructorDescriptionFallback(File file, InvalidPathException cause) Creates a new fallback to use if the given file cannot be converted to aPath. -
Method Summary
Modifier and TypeMethodDescriptioninputStream(String filename, StoreListeners listeners) Opens a new input stream for the file given at construction time.outputStream(String filename, StoreListeners listeners) Opens a new output stream for the file given at construction time.readable(String filename, StoreListeners listeners) Opens a new channel for the file given at construction time.private voidwarning(String method, StoreListeners listeners) Invoked when we have been able to create a channel, but maybe not with the givenOpenOptions.writable(String filename, StoreListeners listeners) Opens a new channel for the file given at construction time.Methods inherited from class org.apache.sis.internal.storage.io.ChannelFactory
canOpen, isCoupled, prepare
-
Field Details
-
file
The file for which to open a channel. -
cause
The reason why we are using this fallback instead of aPath. Will be reported at most once, then set tonull.
-
-
Constructor Details
-
Fallback
Fallback(File file, InvalidPathException cause) Creates a new fallback to use if the given file cannot be converted to aPath.
-
-
Method Details
-
inputStream
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
Fileto aPath. On all subsequent invocations, the file is opened silently.- 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:
IOException- if the input stream or its underlying byte channel cannot be created.
-
outputStream
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
Fileto aPath. On all subsequent invocations, the file is opened silently.- 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:
IOException- if the output stream or its underlying byte channel cannot be created.
-
warning
Invoked when we have been able to create a channel, but maybe not with the givenOpenOptions. Since the exception was nevertheless unexpected, log its stack trace in order to allow the developer to check if there is something wrong. -
readable
Opens a new channel for the file given at construction time.- 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:
IOException- if an error occurred while opening the channel.
-
writable
Opens a new channel for the file given at construction time.- 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:
IOException- if an error occurred while opening the channel.
-