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 InvalidPathException
The reason why we are using this fallback instead of aPath
.private final File
The 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 void
warning
(String method, StoreListeners listeners) Invoked when we have been able to create a channel, but maybe not with the givenOpenOption
s.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
File
to aPath
. On all subsequent invocations, the file is opened silently.- 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:
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
File
to aPath
. On all subsequent invocations, the file is opened silently.- 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:
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 givenOpenOption
s. 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:
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:
IOException
- if an error occurred while opening the channel.
-
writable
Opens a new channel for the file given at construction time.- 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:
IOException
- if an error occurred while opening the channel.
-