}
private static NetcdfFile open(ucar.unidata.io.RandomAccessFile raf, String location, ucar.nc2.util.CancelTask cancelTask,
Object iospMessage) throws IOException {
IOServiceProvider spi = null;
if (debugSPI) System.out.println("NetcdfFile try to open = " + location);
// avoid opening file more than once, so pass around the raf.
if (N3header.isValidFile(raf)) {
spi = SPFactory.getServiceProvider();
//} else if (H5header.isValidFile(raf)) {
// spi = new ucar.nc2.iosp.hdf5.H5iosp();
} else {
// look for registered providers
for (IOServiceProvider registeredSpi : registeredProviders) {
if (debugSPI) System.out.println(" try iosp = " + registeredSpi.getClass().getName());
if (registeredSpi.isValidFile(raf)) {
// need a new instance for thread safety
Class c = registeredSpi.getClass();
try {
spi = (IOServiceProvider) c.newInstance();
} catch (InstantiationException e) {
throw new IOException("IOServiceProvider " + c.getName() + "must have no-arg constructor."); // shouldnt happen
} catch (IllegalAccessException e) {
throw new IOException("IOServiceProvider " + c.getName() + " IllegalAccessException: " + e.getMessage()); // shouldnt happen
}
break;
}
}
}
if (spi == null) {
raf.close();
throw new IOException("Cant read " + location + ": not a valid CDM file.");
}
// send before iosp is opened
if (iospMessage != null)
spi.sendIospMessage(iospMessage);
if (log.isDebugEnabled())
log.debug("Using IOSP " + spi.getClass().getName());
NetcdfFile result = new NetcdfFile(spi, raf, location, cancelTask);
// send after iosp is opened
if (iospMessage != null)
spi.sendIospMessage(iospMessage);
return result;
}