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 StorageConnectorInformation about the storage (URL, stream, etc).(package private) final booleantrueif the file is known to be empty, orfalsein case of doubt.(package private) final booleantrueif the storage seems to be writable.(package private) ObjectTheconnectorobject to keep open if we successfully created aWorldFileStore.(package private) final booleantrueif the storage should be open is write mode instead of read mode.(package private) final WorldFileStoreProviderThe factory that created thisDataStoreinstance, ornullif unspecified.private ImageReaderThe image reader if specified or created by thisFormatFinder, ornull.private booleanWhether we already made an attempt to find the image reader or writer usingImageIOregistry.(package private) final ObjectThe file, URL or stream where to read or write the image.(package private) final StringThe filename extension (may be an empty string), ornullif unknown.private ImageWriterThe image writer if specified or created by thisFormatFinder, ornull.private booleanWhether we already made an attempt to find the image reader or writer usingImageIOregistry. -
Constructor Summary
ConstructorsConstructorDescriptionFormatFinder(WorldFileStoreProvider provider, StorageConnector connector) Creates a new format finder. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclose()Closes all unused resources.(package private) final String[]Returns the name of the format.(package private) final ImageReaderReturns the user-specified reader or searches for a reader that claim to be able to read the storage input.(package private) final ImageWriterReturns the user-specified writer or searches for a writer for the file suffix.private static IOExceptionReturns the cause of given exception if it exists, or the exception itself otherwise.
-
Field Details
-
provider
The factory that created thisDataStoreinstance, ornullif unspecified. -
connector
Information about the storage (URL, stream, etc). -
keepOpen
Object keepOpenTheconnectorobject to keep open if we successfully created aWorldFileStore. This is often the same object thanstoragebut may be different if anImageInputStreamhas been created from the storage object.This value is
nulluntil 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 anImageReaderorImageWriter, 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 usingImageIOregistry. -
writerLookupDone
private boolean writerLookupDoneWhether we already made an attempt to find the image reader or writer usingImageIOregistry. -
isWritable
final boolean isWritabletrueif the storage seems to be writable. -
openAsWriter
final boolean openAsWritertrueif the storage should be open is write mode instead of read mode. This istrueif the file does not exist or the file is empty. -
fileIsEmpty
final boolean fileIsEmptytrueif the file is known to be empty, orfalsein case of doubt. -
suffix
The filename extension (may be an empty string), ornullif 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 thisDataStoreinstance, ornullif unspecified.connector- information about the storage (URL, stream, etc).- Throws:
DataStoreExceptionIOException
-
-
Method Details
-
getFormatName
Returns the name of the format.- Returns:
- name of the format, or
nullif unknown. - Throws:
DataStoreExceptionIOException
-
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
nullif none could be found. - Throws:
DataStoreExceptionIOException
-
getOrCreateWriter
Returns the user-specified writer or searches for a writer for the file suffix.- Returns:
- the writer, or
nullif none could be found. - Throws:
DataStoreExceptionIOException
-
unwrap
Returns the cause of given exception if it exists, or the exception itself otherwise. This method is invoked in thecatchblock of atryblock invokingImageIO.createImageInputStream(Object)orImageIO.createImageOutputStream(Object).Rational
As of Java 18, above-cited methods systematically catch allIOExceptions and wrap them in anIIOExceptionwith "Cannot create cache file!" error message. This is conform to Image I/O specification but misleading if the stream provider throws anIOExceptionfor 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 byWorldFileStoreconstruction.- Specified by:
closein interfaceAutoCloseable- Throws:
DataStoreException
-