コード例 #1
0
  /**
   * Checks availability of a classpath resource.
   *
   * @param name Resource name.
   * @return {@code true} if resource is available and ready for read, {@code false} otherwise.
   */
  private boolean resourceAvailable(String name) {
    InputStream cfgStream =
        Thread.currentThread().getContextClassLoader().getResourceAsStream(name);

    if (cfgStream == null) {
      log.error("Classpath resource not found: " + name);

      return false;
    }

    try {
      // Read a single byte to force actual content access by JVM.
      cfgStream.read();

      return true;
    } catch (IOException e) {
      log.error("Failed to read classpath resource: " + name, e);

      return false;
    } finally {
      U.close(cfgStream, log);
    }
  }