mirror of
https://github.com/TeamPiped/reqwest4j.git
synced 2024-08-14 23:54:39 +00:00
Cleanup tempDir file creation.
This commit is contained in:
parent
4480826b54
commit
1c58bc2dba
1 changed files with 19 additions and 21 deletions
|
@ -1,39 +1,37 @@
|
|||
package rocks.kavin.reqwest4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class ReqwestUtils {
|
||||
|
||||
static {
|
||||
String arch;
|
||||
String arch = switch (System.getProperty("os.arch")) {
|
||||
case "aarch64" -> "aarch64";
|
||||
case "amd64" -> "x86_64";
|
||||
default -> throw new RuntimeException("Unsupported architecture");
|
||||
};
|
||||
|
||||
switch (System.getProperty("os.arch")) {
|
||||
case "aarch64":
|
||||
arch = "aarch64";
|
||||
break;
|
||||
case "amd64":
|
||||
arch = "x86_64";
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unsupported architecture");
|
||||
}
|
||||
File nativeFile;
|
||||
|
||||
String fileName =
|
||||
System.getProperty("java.io.tmpdir") +
|
||||
File.separatorChar +
|
||||
"libreqwest_" + System.currentTimeMillis() + ".so";
|
||||
|
||||
final var cl = ReqwestUtils.class.getClassLoader();
|
||||
|
||||
try (var stream = cl.getResourceAsStream("META-INF/natives/linux/" + arch + "/libreqwest.so")) {
|
||||
stream.transferTo(new java.io.FileOutputStream(fileName));
|
||||
try {
|
||||
nativeFile = File.createTempFile("libreqwest", ".so");
|
||||
nativeFile.deleteOnExit();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
System.load(fileName);
|
||||
final var cl = ReqwestUtils.class.getClassLoader();
|
||||
|
||||
try (var stream = cl.getResourceAsStream("META-INF/natives/linux/" + arch + "/libreqwest.so")) {
|
||||
stream.transferTo(new FileOutputStream(nativeFile));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
System.load(nativeFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
public static native Response fetch(String url, String method, byte[] body,
|
||||
|
|
Loading…
Reference in a new issue