24
24
import java .io .File ;
25
25
import java .io .FileNotFoundException ;
26
26
import java .io .FileOutputStream ;
27
- import java .io .IOException ;
28
27
import java .io .InputStream ;
29
28
import java .io .OutputStream ;
29
+ import java .nio .file .Files ;
30
+ import java .nio .file .Path ;
31
+ import lombok .NonNull ;
30
32
import lombok .experimental .UtilityClass ;
31
33
32
34
/**
@@ -46,17 +48,17 @@ public class NativeUtils {
46
48
value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" ,
47
49
justification = "work around for java 9: https://github.com/spotbugs/spotbugs/issues/493" )
48
50
public static void loadLibraryFromJar (String path ) throws Exception {
49
- com . google . common . base . Preconditions . checkArgument (path .startsWith ("/" ), "absolute path must start with /" );
51
+ checkArgument (path .startsWith ("/" ), "absolute path must start with /" );
50
52
51
53
String [] parts = path .split ("/" );
52
- String filename = (parts .length > 0 ) ? parts [ parts . length - 1 ] : null ;
54
+ checkArgument (parts .length > 0 , "absolute path must contain file name" ) ;
53
55
54
- File dir = File . createTempFile ( "native" , "" ) ;
55
- if (!( dir . mkdir ())) {
56
- throw new IOException ( "Failed to create temp directory " + dir . getAbsolutePath ());
57
- }
58
- dir .deleteOnExit ();
59
- File temp = new File (dir , filename );
56
+ String filename = parts [ parts . length - 1 ] ;
57
+ checkArgument ( path . startsWith ( "/" ), "absolute path must start with /" );
58
+
59
+ Path dir = Files . createTempDirectory ( "native" );
60
+ dir .toFile (). deleteOnExit ();
61
+ File temp = new File (dir . toString () , filename );
60
62
temp .deleteOnExit ();
61
63
62
64
byte [] buffer = new byte [1024 ];
@@ -79,4 +81,10 @@ public static void loadLibraryFromJar(String path) throws Exception {
79
81
80
82
System .load (temp .getAbsolutePath ());
81
83
}
84
+
85
+ private static void checkArgument (boolean expression , @ NonNull Object errorMessage ) {
86
+ if (!expression ) {
87
+ throw new IllegalArgumentException (String .valueOf (errorMessage ));
88
+ }
89
+ }
82
90
}
0 commit comments