public static void loadTempBinaryFile(String libName) throws Exception {
        String libPrefix = createLibPrefix();
        String libExtension = createLibExtension();
        String fullName = libPrefix + libName;
        String resourceName = fullName + "." + libExtension;
        ClassPathResource resource = new ClassPathResource(resourceName);
        InputStream inputStream = resource.getInputStream();
        if (inputStream == null) {
            throw new NullPointerException("No resource found with name '" + resourceName + "'");
        }

        File tempFile = new File(System.getProperty("java.io.tmpdir"), fullName + "." + libExtension);
        tempFile.deleteOnExit();
        OutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(tempFile);
            byte[] buffer = new byte[8192];
            while (true) {
                int read = inputStream.read(buffer);
                if (read < 0) {
                    break;
                }
                outputStream.write(buffer, 0, read);
            }
            outputStream.flush();
            outputStream.close();
            outputStream = null;

            System.load(tempFile.getAbsolutePath());
        } finally {
            if (outputStream != null) {
                outputStream.close();
            }
        }
    }
public static void loadTempBinaryFile ( String libName ) throws Exception { String libPrefix = createLibPrefix ( ) ; String libExtension = createLibExtension ( ) ; String fullName = libPrefix + libName ; String resourceName = fullName + "." + libExtension ; ClassPathResource resource = new ClassPathResource ( resourceName ) ; InputStream inputStream = resource . getInputStream ( ) ; if ( inputStream == null ) { throw new NullPointerException ( "No resource found with name '" + resourceName + "'" ) ; } File tempFile = new File ( System . getProperty ( "java.io.tmpdir" ) , fullName + "." + libExtension ) ; tempFile . deleteOnExit ( ) ; OutputStream outputStream = null ; try { outputStream = new FileOutputStream ( tempFile ) ; byte [ ] buffer = new byte [ 8192 ] ; while ( true ) { int read = inputStream . read ( buffer ) ; if ( read < 0 ) { break ; } outputStream . write ( buffer , 0 , read ) ; } outputStream . flush ( ) ; outputStream . close ( ) ; outputStream = null ; System . load ( tempFile . getAbsolutePath ( ) ) ; } finally { if ( outputStream != null ) { outputStream . close ( ) ; } } }
Load the library with the given name from a resource.
The extension for the current OS will be appended.

@param libName The library name
@throws Throwable If the library could not be loaded