private static File extractLibraryFile(String libFolderForCurrentOS,
      String libraryFileName, String targetFolder) {
    String nativeLibraryFilePath = libFolderForCurrentOS + "/" + libraryFileName;
    File extractedLibFile = new File(targetFolder, libraryFileName);

    try {
      if (extractedLibFile.exists()) {
        // test md5sum value
        String md5sum1 = md5sum(NativeLoader.class
            .getResourceAsStream(nativeLibraryFilePath));
        String md5sum2 = md5sum(new FileInputStream(extractedLibFile));

        if (md5sum1.equals(md5sum2)) {
          return extractedLibFile;
        } else {
          // remove old native library file
          boolean deletionSucceeded = extractedLibFile.delete();
          if (!deletionSucceeded) {
            throw new IOException("failed to remove existing native library file: "
                + extractedLibFile.getAbsolutePath());
          }
        }
      }

      // Extract a native library file into the target directory
      InputStream reader = NativeLoader.class
          .getResourceAsStream(nativeLibraryFilePath);
      FileOutputStream writer = new FileOutputStream(extractedLibFile);
      byte[] buffer = new byte[8192];
      int bytesRead = 0;
      while ((bytesRead = reader.read(buffer)) != -1) {
        writer.write(buffer, 0, bytesRead);
      }

      writer.close();
      reader.close();

      // Set executable (x) flag to enable Java to load the native library
      if (!System.getProperty("os.name").contains("Windows")) {
        try {
          Runtime
              .getRuntime()
              .exec(
                  new String[] { "chmod", "755", extractedLibFile.getAbsolutePath() })
              .waitFor();
        } catch (Throwable e) {
        }
      }

      return extractedLibFile;
    } catch (IOException e) {
      e.printStackTrace(System.err);
      return null;
    }
  }