Search in sources :

Example 6 with ProbeResult

use of org.apache.sis.storage.ProbeResult in project sis by apache.

the class NetcdfStoreProviderTest method testProbeContentFromUCAR.

/**
 * Tests {@link NetcdfStoreProvider#probeContent(StorageConnector)} for a UCAR {@link NetcdfFile} object.
 *
 * @throws IOException if an error occurred while opening the netCDF file.
 * @throws DataStoreException if a logical error occurred.
 */
@Test
public void testProbeContentFromUCAR() throws IOException, DataStoreException {
    try (NetcdfFile file = open(NCEP)) {
        final StorageConnector c = new StorageConnector(file);
        final NetcdfStoreProvider provider = new NetcdfStoreProvider();
        final ProbeResult probe = provider.probeContent(c);
        assertTrue("isSupported", probe.isSupported());
        assertEquals("getMimeType", NetcdfStoreProvider.MIME_TYPE, probe.getMimeType());
        assertNull("getVersion", probe.getVersion());
    }
}
Also used : NetcdfFile(ucar.nc2.NetcdfFile) StorageConnector(org.apache.sis.storage.StorageConnector) ProbeResult(org.apache.sis.storage.ProbeResult) ChannelDecoderTest(org.apache.sis.internal.netcdf.impl.ChannelDecoderTest) Test(org.junit.Test)

Example 7 with ProbeResult

use of org.apache.sis.storage.ProbeResult in project sis by apache.

the class StoreProviderTest method testProbeContentFromReader.

/**
 * Tests {@link StoreProvider#probeContent(StorageConnector)} method from a {@link java.io.Reader} object.
 *
 * @throws DataStoreException if en error occurred while reading the XML.
 */
@Test
public void testProbeContentFromReader() throws DataStoreException {
    final StoreProvider p = new StoreProvider();
    final StorageConnector c = new StorageConnector(new StringReader(StoreTest.XML));
    final ProbeResult r = p.probeContent(c);
    c.closeAllExcept(null);
    assertTrue("isSupported", r.isSupported());
    assertEquals("mimeType", "application/vnd.iso.19139+xml", r.getMimeType());
}
Also used : StorageConnector(org.apache.sis.storage.StorageConnector) StringReader(java.io.StringReader) ProbeResult(org.apache.sis.storage.ProbeResult) Test(org.junit.Test)

Example 8 with ProbeResult

use of org.apache.sis.storage.ProbeResult in project sis by apache.

the class GeoTiffStoreProvider method probeContent.

/**
 * Returns {@link ProbeResult#SUPPORTED} if the given storage appears to be supported by {@link GeoTiffStore}.
 * Returning {@code SUPPORTED} from this method does not guarantee that reading or writing will succeed,
 * only that there appears to be a reasonable chance of success based on a brief inspection of the
 * {@linkplain StorageConnector#getStorage() storage object} or contents.
 *
 * @param  connector  information about the storage (URL, stream, <i>etc</i>).
 * @return {@code SUPPORTED} if the given storage seems to be usable by {@code GeoTiffStore} instances.
 * @throws DataStoreException if an I/O error occurred.
 */
@Override
public ProbeResult probeContent(StorageConnector connector) throws DataStoreException {
    final ByteBuffer buffer = connector.getStorageAs(ByteBuffer.class);
    if (buffer != null) {
        if (buffer.remaining() < 2 * Short.BYTES) {
            return ProbeResult.INSUFFICIENT_BYTES;
        }
        final int p = buffer.position();
        final short order = buffer.getShort(p);
        final boolean isBigEndian = (order == GeoTIFF.BIG_ENDIAN);
        if (isBigEndian || order == GeoTIFF.LITTLE_ENDIAN) {
            final ByteOrder old = buffer.order();
            try {
                buffer.order(isBigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
                switch(buffer.getShort(p + Short.BYTES)) {
                    case GeoTIFF.CLASSIC:
                    case GeoTIFF.BIG_TIFF:
                        return new ProbeResult(true, MIME_TYPE, VERSION);
                }
            } finally {
                buffer.order(old);
            }
        }
    }
    return ProbeResult.UNSUPPORTED_STORAGE;
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer) ProbeResult(org.apache.sis.storage.ProbeResult)

Aggregations

ProbeResult (org.apache.sis.storage.ProbeResult)8 StorageConnector (org.apache.sis.storage.StorageConnector)4 ByteBuffer (java.nio.ByteBuffer)3 DataStoreException (org.apache.sis.storage.DataStoreException)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ChannelDecoderTest (org.apache.sis.internal.netcdf.impl.ChannelDecoderTest)2 FileNotFoundException (java.io.FileNotFoundException)1 Reader (java.io.Reader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ByteOrder (java.nio.ByteOrder)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Version (org.apache.sis.util.Version)1 NetcdfFile (ucar.nc2.NetcdfFile)1