Search in sources :

Example 1 with Decoder

use of org.apache.sis.internal.netcdf.Decoder in project sis by apache.

the class MetadataReaderTest method testEmbedded.

/**
 * Reads the metadata using the netCDF decoder embedded with SIS,
 * and compares its string representation with the expected one.
 *
 * @throws IOException if an I/O error occurred while opening the file.
 * @throws DataStoreException if a logical error occurred.
 */
@Test
public void testEmbedded() throws IOException, DataStoreException {
    final Metadata metadata;
    try (Decoder input = ChannelDecoderTest.createChannelDecoder(NCEP)) {
        metadata = new MetadataReader(input).read();
    }
    compareToExpected(metadata);
}
Also used : DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) Metadata(org.opengis.metadata.Metadata) Decoder(org.apache.sis.internal.netcdf.Decoder) ChannelDecoderTest(org.apache.sis.internal.netcdf.impl.ChannelDecoderTest) Test(org.junit.Test)

Example 2 with Decoder

use of org.apache.sis.internal.netcdf.Decoder 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)

Example 3 with Decoder

use of org.apache.sis.internal.netcdf.Decoder in project sis by apache.

the class MetadataReaderTest method testUCAR.

/**
 * Reads the metadata using the UCAR library and compares
 * its string representation with the expected one.
 *
 * @throws IOException if an I/O error occurred.
 * @throws DataStoreException if a logical error occurred.
 */
@Test
public void testUCAR() throws IOException, DataStoreException {
    final Metadata metadata;
    try (Decoder input = new DecoderWrapper(new NetcdfDataset(open(NCEP)), GeometryLibrary.JAVA2D, TestCase.LISTENERS)) {
        metadata = new MetadataReader(input).read();
    }
    compareToExpected(metadata);
}
Also used : DecoderWrapper(org.apache.sis.internal.netcdf.ucar.DecoderWrapper) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) Metadata(org.opengis.metadata.Metadata) NetcdfDataset(ucar.nc2.dataset.NetcdfDataset) Decoder(org.apache.sis.internal.netcdf.Decoder) ChannelDecoderTest(org.apache.sis.internal.netcdf.impl.ChannelDecoderTest) Test(org.junit.Test)

Aggregations

Decoder (org.apache.sis.internal.netcdf.Decoder)3 ChannelDecoderTest (org.apache.sis.internal.netcdf.impl.ChannelDecoderTest)2 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)2 Test (org.junit.Test)2 Metadata (org.opengis.metadata.Metadata)2 ChannelDecoder (org.apache.sis.internal.netcdf.impl.ChannelDecoder)1 DecoderWrapper (org.apache.sis.internal.netcdf.ucar.DecoderWrapper)1 ChannelDataInput (org.apache.sis.internal.storage.io.ChannelDataInput)1 GeometryLibrary (org.apache.sis.setup.GeometryLibrary)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 NetcdfDataset (ucar.nc2.dataset.NetcdfDataset)1