use of org.apache.sis.setup.GeometryLibrary in project sis by apache.
the class NetcdfStoreProvider method decoder.
/**
* Creates a decoder for the given input. This method invokes
* {@link StorageConnector#closeAllExcept(Object)} after the decoder has been created.
*
* @param listeners where to send the warnings.
* @param connector information about the input (file, input stream, <i>etc.</i>)
* @return the decoder for the given input, or {@code null} if the input type is not recognized.
* @throws IOException if an error occurred while opening the netCDF file.
* @throws DataStoreException if a logical error (other than I/O) occurred.
*/
static Decoder decoder(final WarningListeners<DataStore> listeners, final StorageConnector connector) throws IOException, DataStoreException {
final GeometryLibrary geomlib = connector.getOption(OptionKey.GEOMETRY_LIBRARY);
Decoder decoder;
Object keepOpen;
final ChannelDataInput input = connector.getStorageAs(ChannelDataInput.class);
if (input != null)
try {
decoder = new ChannelDecoder(input, connector.getOption(OptionKey.ENCODING), geomlib, listeners);
keepOpen = input;
} catch (DataStoreException e) {
final String path = connector.getStorageAs(String.class);
if (path != null)
try {
decoder = createByReflection(path, false, geomlib, listeners);
keepOpen = path;
} catch (IOException | DataStoreException s) {
e.addSuppressed(s);
}
throw e;
}
else {
keepOpen = connector.getStorage();
decoder = createByReflection(keepOpen, true, geomlib, listeners);
}
connector.closeAllExcept(keepOpen);
return decoder;
}
Aggregations