static public Optional<FeatureDatasetCoverage> openGrib(String endpoint) throws IOException {

    List<Object> notGribThrowables = Arrays.asList(
            IllegalAccessException.class,
            IllegalArgumentException.class,
            ClassNotFoundException.class,
            NoSuchMethodException.class,
            NoSuchMethodError.class);

    try {
      Class<?> c = CoverageDatasetFactory.class.getClassLoader().loadClass("ucar.nc2.grib.coverage.GribCoverageDataset");
      Method method = c.getMethod("open", String.class);
      return (Optional<FeatureDatasetCoverage>) method.invoke(null, endpoint);
    } catch (Exception e) {
      for (Object noGrib : notGribThrowables) {
        // check for possible errors that are due to the file not being grib. Need to look
        // at the error causes too, as reflection error can be buried under a InvorcationTargetException
        boolean notGribTopLevel = e.getClass().equals(noGrib);
        boolean notGribBuried = e.getClass().equals(InvocationTargetException.class) &&
                                e.getCause() != null &&
                                e.getCause().getClass().equals(noGrib);

        if (notGribTopLevel || notGribBuried) {
          return Optional.empty(NO_GRIB_CLASS);
        }
      }
      // Ok, something went wrong, and it does not appear to be related to the file *not* being
      // a grib file.
      return Optional.empty(e.getCause().getMessage());
    }

  }
static public Optional < FeatureDatasetCoverage > openGrib ( String endpoint ) throws IOException { List < Object > notGribThrowables = Arrays . asList ( IllegalAccessException . class , IllegalArgumentException . class , ClassNotFoundException . class , NoSuchMethodException . class , NoSuchMethodError . class ) ; try { Class < ? > c = CoverageDatasetFactory . class . getClassLoader ( ) . loadClass ( "ucar.nc2.grib.coverage.GribCoverageDataset" ) ; Method method = c . getMethod ( "open" , String . class ) ; return ( Optional < FeatureDatasetCoverage > ) method . invoke ( null , endpoint ) ; } catch ( Exception e ) { for ( Object noGrib : notGribThrowables ) { boolean notGribTopLevel = e . getClass ( ) . equals ( noGrib ) ; boolean notGribBuried = e . getClass ( ) . equals ( InvocationTargetException . class ) && e . getCause ( ) != null && e . getCause ( ) . getClass ( ) . equals ( noGrib ) ; if ( notGribTopLevel || notGribBuried ) { return Optional . empty ( NO_GRIB_CLASS ) ; } } return Optional . empty ( e . getCause ( ) . getMessage ( ) ) ; } }
@param endpoint local GRIB data or index file
@return FeatureDatasetCoverage or null on failure.
@throws IOException