-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloWorld.java
More file actions
80 lines (75 loc) · 2.43 KB
/
Copy pathHelloWorld.java
File metadata and controls
80 lines (75 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class HelloWorld {
static String DLL_NAME="libHelloWorld.dll";
static {
// System.loadLibrary("libHelloWorld");
System.load("F:\\RcpWorkspace\\r1\\HelloWorld\\src\\lib-bin\\libHelloWorld.dll");
// loadFromJar();
}
public HelloWorld() {
}
private static void loadFromJar() throws UnsatisfiedLinkError
{
File tempDir = new File(System.getProperty("user.dir"));
File dllFile = new File(tempDir, DLL_NAME);
// Thubby: This returns null for me!
//InputStream in = JNative.class.getResourceAsStream("../../../lib-bin/" + DLL_NAME);
InputStream in = HelloWorld.class.getResourceAsStream("/lib-bin/" + DLL_NAME);
if (in == null)
{
if (!dllFile.exists())
{
throw new UnsatisfiedLinkError(DLL_NAME + " : unable to find in " + tempDir);
}
}
else
{
if (dllFile.exists() && dllFile.canWrite())
{
dllFile.delete();
}
if (!dllFile.exists())
{
byte[] buffer = new byte[512];
BufferedOutputStream out = null;
try
{
try
{
out = new BufferedOutputStream(new FileOutputStream(dllFile));
while (true)
{
int readed = in.read(buffer);
if (readed > -1)
{
out.write(buffer, 0, readed);
}
else
{
break;
}
}
}
finally
{
if (out != null)
{
out.close();
}
}
}
catch (IOException e)
{
throw new UnsatisfiedLinkError("Can't write library in " + dllFile);
}
}
System.load(dllFile.toString());
}
}
public native int init(int lPort);
public native void print(String str);
}