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());
}
}
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());
}
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;
}
Aggregations