private void loadFromPath()

in geronimo-metrics-extensions/geronimo-metrics-sigar/src/main/java/org/apache/geronimo/microprofile/metrics/extension/sigar/InitSigar.java [56:93]


    private void loadFromPath(final SigarLoader loader) {
        try {
            final String systemProp = loader.getPackageName() + ".path";
            final String path = System.getProperty(systemProp);
            if (path == null) {
                final String libraryName = loader.getLibraryName();
                final File output = new File(tempDir, "sigar/" + libraryName);
                if (!output.exists()) {
                    final int dot = libraryName.lastIndexOf('.');
                    final String resourceName = libraryName.substring(0, dot) + "-"
                            + System.getProperty("sigar.version", "1.6.4") + libraryName.substring(dot);
                    try (final InputStream stream = Thread.currentThread().getContextClassLoader()
                                                          .getResourceAsStream(resourceName)) {
                        if (stream != null) {
                            output.getParentFile().mkdirs();
                            Files.copy(stream, output.toPath(), StandardCopyOption.REPLACE_EXISTING);
                        } else {
                            unavailable("native library not found in the classloader as " + resourceName);
                            return;
                        }
                        loader.load(output.getParentFile().getAbsolutePath());
                        afterLoad(systemProp);
                    } catch (final ArchLoaderException | IOException ex) {
                        unavailable(ex.getMessage());
                    }
                }
            } else if (!"-".equals(path)) {
                try {
                    loader.load(path);
                    afterLoad(systemProp);
                } catch (final ArchLoaderException ex) {
                    unavailable(ex.getMessage());
                }
            }
        } catch (final ArchNotSupportedException ex) {
            unavailable(ex.getMessage());
        }
    }