public CompletableFuture executeOpenFile()

in hadoop-api-shim/src/main/java/org/apache/hadoop/fs/shim/impl/OpenFileThroughBuilderAPI.java [118:165]


  public CompletableFuture<FSDataInputStream> executeOpenFile(final OpenFileBuilder source)
      throws IllegalArgumentException, UnsupportedOperationException, IOException {

    FileSystem fs = getInstance();
    Path path = fs.makeQualified(source.getPath());
    LOG.debug("Opening file at {} through builder API", path);

    try {
      Object builder = openFileMethod.invoke(fs, path);
      Class<?> builderClass = builder.getClass();
      // optional paraketers
      Method opt = builderClass.getMethod("opt", String.class, String.class);
      Configuration options = source.getOptions();
      for (Map.Entry<String, String> option : options) {
        opt.invoke(builder, option.getKey(), option.getValue());
      }
      // mandatory parameters
      Method must = builderClass.getMethod("must", String.class, String.class);
      for (String k : source.getMandatoryKeys()) {
        must.invoke(builder, k, options.get(k));
      }
      Method build = builderClass.getMethod("build");
      build.setAccessible(true);
      Object result = build.invoke(builder);
      // cast and return. may raise ClassCastException which will
      // be thrown.
      CompletableFuture<FSDataInputStream> future = (CompletableFuture<FSDataInputStream>) result;

      return future;

    } catch (ClassCastException e) {
      // this a bug in the code, rethrow
      openFileException(path, e);
      throw e;
    } catch (InvocationTargetException e) {
      // an exception was reaised by the method, so examine it
      // this is not something to consider an API failure
      final IOException ioe = FutureIO.unwrapInnerException(e);
      LOG.debug("Openfile failure for {}", path, ioe);
      throw ioe;

    } catch (IllegalAccessException | NoSuchMethodException e) {
      // downgrade on all failures, even classic IOEs...let the fallback handle them.
      openFileException(path, e);
      throw new UnsupportedOperationException(e);
    }

  }