Skip to content

Commit

Permalink
While here, simplify loading embedded library.
Browse files Browse the repository at this point in the history
Signed-off-by: Kenneth J. Shackleton <[email protected]>
  • Loading branch information
kennethshackleton committed Feb 11, 2024
1 parent 4c1d0c9 commit f8cacc8
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.bloomberg.selekt.commons

import java.io.BufferedOutputStream
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
Expand Down Expand Up @@ -67,10 +66,12 @@ fun loadEmbeddedLibrary(loader: ClassLoader, parentDirectory: String, name: Stri
loader.getResource(it)
}) { "Failed to find resource with name: $name in directory: $parentDirectory" }
@Suppress("NewApi") // Not used by Android.
val file = createTempFile("lib$name", "lib").toFile().apply { deleteOnExit() }
val file = createTempFile("lib$name", "lib").toFile()
try {
url.openStream().use { inputStream ->
BufferedOutputStream(FileOutputStream(file)).use { outputStream -> inputStream.copyTo(outputStream) }
FileOutputStream(file).use {
inputStream.copyTo(it)
}
}
@Suppress("UnsafeDynamicallyLoadedCode")
System.load(file.absolutePath)
Expand Down

0 comments on commit f8cacc8

Please sign in to comment.