code: private void loadLibraryFromStream(String libname, InputStream is) {
      try {
        File tempfile = createTempFile(libname);
        OutputStream os = new FileOutputStream(tempfile);
  
        logger.debug("tempfile.getPath() = " + tempfile.getPath());
  
        long savedTime = System.currentTimeMillis();
  
        // Leo says 8k block size is STANDARD ;)
        byte buf[] = new byte[8192];
        int len;
        while ((len = is.read(buf)) > 0) {
          os.write(buf, 0, len);
        }
  
        os.flush();
        InputStream lock = new FileInputStream(tempfile);
        os.close();
  
        double seconds = (double) (System.currentTimeMillis() - savedTime) / 1e3;
        logger.debug("Copying took " + seconds + " seconds.");
  
        logger.debug("Loading library from " + tempfile.getPath() + ".");
        System.load(tempfile.getPath());
  
        lock.close();
      } catch (IOException io) {
        logger.error("Could not create the temp file: " + io.toString() + ".\n");
      } catch (UnsatisfiedLinkError ule) {
        logger.error("Couldn't load copied link file: " + ule.toString() + ".\n");
        throw ule;
      }
    }
docs: Load a system library from a stream. Copies the library to a temp file
  and loads from there.
  
  @param libname name of the library (just used in constructing the library name)
  @param is      InputStream pointing to the library