code: public static void finishIfApplicable(Iterable<?> toFinish) throws IOException {
      for (final Object o : toFinish) {
        if (o instanceof Finishable) {
          ((Finishable) o).finish();
        }
      }
    }
docs: Calls {@link Finishable#finish()} on all objects provided which implement {@link Finishable}