Search in sources :

Example 1 with GeometryLibrary

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;
}
Also used : GeometryLibrary(org.apache.sis.setup.GeometryLibrary) ChannelDecoder(org.apache.sis.internal.netcdf.impl.ChannelDecoder) DataStoreException(org.apache.sis.storage.DataStoreException) Decoder(org.apache.sis.internal.netcdf.Decoder) ChannelDecoder(org.apache.sis.internal.netcdf.impl.ChannelDecoder) ChannelDataInput(org.apache.sis.internal.storage.io.ChannelDataInput)

Aggregations

Decoder (org.apache.sis.internal.netcdf.Decoder)1 ChannelDecoder (org.apache.sis.internal.netcdf.impl.ChannelDecoder)1 ChannelDataInput (org.apache.sis.internal.storage.io.ChannelDataInput)1 GeometryLibrary (org.apache.sis.setup.GeometryLibrary)1 DataStoreException (org.apache.sis.storage.DataStoreException)1