public static synchronized void provision ( final File folder ) throws Exception { if ( isNativeLoaded ( ) ) { logger . warning ( "Sigar library is already provisioned." ) ; return ; } if ( ! folder . exists ( ) ) { folder . mkdirs ( ) ; } final SigarLoader sigarLoader = new SigarLoader ( Sigar . class ) ; /** Library name for given architecture. */ final String libraryName = sigarLoader . getLibraryName ( ) ; /** Library location embedded in the jar class path. */ final String sourcePath = "/" + LIB_DIR + "/" + libraryName ; /** Absolute path to the extracted library the on file system. */ final File targetPath = new File ( folder , libraryName ) . getAbsoluteFile ( ) ; /** Extract library form the jar to the local file system. */ final InputStream sourceStream = SigarProvisioner . class . getResourceAsStream ( sourcePath ) ; final OutputStream targetStream = new FileOutputStream ( targetPath ) ; transfer ( sourceStream , targetStream ) ; sourceStream . close ( ) ; targetStream . close ( ) ; /** Load library via absolute path. */ final String libraryPath = targetPath . getAbsolutePath ( ) ; System . load ( libraryPath ) ; /** Tell sigar loader that the library is already loaded. */ System . setProperty ( "org.hyperic.sigar.path" , "-" ) ; sigarLoader . load ( ) ; logger . info ( "Sigar library provisioned: " + libraryPath ) ; }
Extract and load native sigar library in the provided folder .