mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-12-22 18:21:51 +01:00
Update NativeUtils.java
This commit is contained in:
parent
ec83d01dca
commit
76089a3466
@ -19,23 +19,20 @@ public final class NativeUtils {
|
||||
}
|
||||
|
||||
private static File unpackLibraryFromJarInternal(String path) throws IOException {
|
||||
if (null == path || !path.startsWith("/")) {
|
||||
Objects.requireNonNull(path, "The path cannot be null.");
|
||||
if (!path.startsWith("/")) {
|
||||
throw new IllegalArgumentException("The path has to be absolute (start with '/').");
|
||||
}
|
||||
|
||||
String[] parts = path.split("/");
|
||||
String filename = (parts.length > 1) ? parts[parts.length - 1] : null;
|
||||
String filename = parts.length > 1 ? parts[parts.length - 1] : null;
|
||||
|
||||
if (filename == null || filename.length() < MIN_PREFIX_LENGTH) {
|
||||
throw new IllegalArgumentException("The filename has to be at least 3 characters long.");
|
||||
}
|
||||
|
||||
if (temporaryDir == null) {
|
||||
temporaryDir = createTempDirectory(NATIVE_FOLDER_PATH_PREFIX);
|
||||
temporaryDir.deleteOnExit();
|
||||
}
|
||||
|
||||
File temp = new File(temporaryDir, filename);
|
||||
File temp = Files.createTempFile(NATIVE_FOLDER_PATH_PREFIX, filename).toFile();
|
||||
temp.deleteOnExit();
|
||||
|
||||
try (InputStream is = NativeUtils.class.getResourceAsStream(path)) {
|
||||
Files.copy(is, temp.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
@ -48,7 +45,7 @@ public final class NativeUtils {
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack library from JAR into temporary path
|
||||
|
Loading…
Reference in New Issue
Block a user