| 179 | } |
| 180 | |
| 181 | public static void loadLib(String lib, @NotNull InputStream libStream) { |
| 182 | try { |
| 183 | File tempLib = null; |
| 184 | try { |
| 185 | int dot = lib.indexOf('.'); |
| 186 | tempLib = File.createTempFile(lib.substring(0, dot), lib.substring(dot)); |
| 187 | // copy to tempLib |
| 188 | try (FileOutputStream out = new FileOutputStream(tempLib)) { |
| 189 | byte[] buf = new byte[4096]; |
| 190 | while (true) { |
| 191 | int read = libStream.read(buf); |
| 192 | if (read == -1) { |
| 193 | break; |
| 194 | } |
| 195 | out.write(buf, 0, read); |
| 196 | } |
| 197 | } finally { |
| 198 | tempLib.deleteOnExit(); |
| 199 | } |
| 200 | System.load(tempLib.getAbsolutePath()); |
| 201 | } catch (IOException e) { |
| 202 | throw new FatalError("Internal error: cannot unpack " + tempLib, e); |
| 203 | } |
| 204 | } finally { |
| 205 | Misc.free(libStream); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | public static native long malloc(long size); |
| 210 | |