Class FormatFinder
java.lang.Object
org.apache.sis.internal.storage.image.FormatFinder
- All Implemented Interfaces:
AutoCloseable
Helper class for finding the
ImageReader
or ImageWriter
instance to use.
This is a temporary object used only at WorldFileStore
construction time.
It also helps to choose which WorldFileStore
subclass to instantiate.- Since:
- 1.2
- Version:
- 1.3
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final StorageConnector
Information about the storage (URL, stream, etc).(package private) final boolean
true
if the file is known to be empty, orfalse
in case of doubt.(package private) final boolean
true
if the storage seems to be writable.(package private) Object
Theconnector
object to keep open if we successfully created aWorldFileStore
.(package private) final boolean
true
if the storage should be open is write mode instead of read mode.(package private) final WorldFileStoreProvider
The factory that created thisDataStore
instance, ornull
if unspecified.private ImageReader
The image reader if specified or created by thisFormatFinder
, ornull
.private boolean
Whether we already made an attempt to find the image reader or writer usingImageIO
registry.(package private) final Object
The file, URL or stream where to read or write the image.(package private) final String
The filename extension (may be an empty string), ornull
if unknown.private ImageWriter
The image writer if specified or created by thisFormatFinder
, ornull
.private boolean
Whether we already made an attempt to find the image reader or writer usingImageIO
registry. -
Constructor Summary
ConstructorsConstructorDescriptionFormatFinder
(WorldFileStoreProvider provider, StorageConnector connector) Creates a new format finder. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
close()
Closes all unused resources.(package private) final String[]
Returns the name of the format.(package private) final ImageReader
Returns the user-specified reader or searches for a reader that claim to be able to read the storage input.(package private) final ImageWriter
Returns the user-specified writer or searches for a writer for the file suffix.private static IOException
Returns the cause of given exception if it exists, or the exception itself otherwise.
-
Field Details
-
provider
The factory that created thisDataStore
instance, ornull
if unspecified. -
connector
Information about the storage (URL, stream, etc). -
keepOpen
Object keepOpenTheconnector
object to keep open if we successfully created aWorldFileStore
. This is often the same object thanstorage
but may be different if anImageInputStream
has been created from the storage object.This value is
null
until successful instantiation of image reader or writer. A null value means to close everything, which is the desired behavior in case of failure. -
storage
The file, URL or stream where to read or write the image. If the user-specified storage was anImageReader
orImageWriter
, then the value stored in this field is the input/output of the reader/writer. -
reader
The image reader if specified or created by thisFormatFinder
, ornull
. -
writer
The image writer if specified or created by thisFormatFinder
, ornull
. -
readerLookupDone
private boolean readerLookupDoneWhether we already made an attempt to find the image reader or writer usingImageIO
registry. -
writerLookupDone
private boolean writerLookupDoneWhether we already made an attempt to find the image reader or writer usingImageIO
registry. -
isWritable
final boolean isWritabletrue
if the storage seems to be writable. -
openAsWriter
final boolean openAsWritertrue
if the storage should be open is write mode instead of read mode. This istrue
if the file does not exist or the file is empty. -
fileIsEmpty
final boolean fileIsEmptytrue
if the file is known to be empty, orfalse
in case of doubt. -
suffix
The filename extension (may be an empty string), ornull
if unknown. It does not include the leading dot.
-
-
Constructor Details
-
FormatFinder
FormatFinder(WorldFileStoreProvider provider, StorageConnector connector) throws DataStoreException, IOException Creates a new format finder.- Parameters:
provider
- the factory that created thisDataStore
instance, ornull
if unspecified.connector
- information about the storage (URL, stream, etc).- Throws:
DataStoreException
IOException
-
-
Method Details
-
getFormatName
Returns the name of the format.- Returns:
- name of the format, or
null
if unknown. - Throws:
DataStoreException
IOException
-
getOrCreateReader
Returns the user-specified reader or searches for a reader that claim to be able to read the storage input. This method tries first the readers associated to the file suffix. If no reader is found, then this method tries all other readers.- Returns:
- the reader, or
null
if none could be found. - Throws:
DataStoreException
IOException
-
getOrCreateWriter
Returns the user-specified writer or searches for a writer for the file suffix.- Returns:
- the writer, or
null
if none could be found. - Throws:
DataStoreException
IOException
-
unwrap
Returns the cause of given exception if it exists, or the exception itself otherwise. This method is invoked in thecatch
block of atry
block invokingImageIO.createImageInputStream(Object)
orImageIO.createImageOutputStream(Object)
.Rational
As of Java 18, above-cited methods systematically catch allIOException
s and wrap them in anIIOException
with "Cannot create cache file!" error message. This is conform to Image I/O specification but misleading if the stream provider throws anIOException
for another reason. Even when the failure is really caused by a problem with cache file, we want to propagate the original exception to user because its message may tell that there is no space left on device or no write permission.- See Also:
-
close
Closes all unused resources. Keep open only the find of objects needed by the image reader or writer. This method must be invoked after byWorldFileStore
construction.- Specified by:
close
in interfaceAutoCloseable
- Throws:
DataStoreException
-