1 package com.neuronrobotics.imageprovider;
3 import java.io.BufferedInputStream;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.io.InputStream;
16 if(System.getProperty(libraryName +
".userlib") !=
null) {
18 if(System.getProperty(libraryName +
".userlib").equalsIgnoreCase(
"sys")) {
19 System.loadLibrary(libraryName);
21 System.load(System.getProperty(libraryName +
".userlib"));
24 }
catch (Exception e){
26 throw new NativeResourceException(
"Unable to load native resource from given path.\n" + e.getLocalizedMessage());
37 File resourceLocation;
39 resourceLocation =
inJarLoad(resourceSource,name);
42 }
catch (IOException e) {
48 @SuppressWarnings(
"rawtypes")
49 public static File
inJarLoad(Class inputClass, String name) throws IOException{
50 InputStream resourceSource = inputClass.getResourceAsStream(name);
56 return resourceLocation;
58 public static File
inJarLoad(InputStream inputStream, String name)
throws IOException{
59 InputStream resourceSource = inputStream;
65 return resourceLocation;
84 file=
"/native/osx/" + name;
87 file=
"/native/windows/x86_64/" + name;
89 file=
"/native/windows/x86_32/" + name;
93 file =
"/native/linux/ARM/" + name;
96 file=
"/native/linux/x86_64/" + name;
98 file=
"/native/linux/x86_32/" + name;
102 System.err.println(
"Can't load native file: "+name+
" for os arch: "+
getOsArch());
106 return getClass().getResourceAsStream(file);
110 if(!resource.canRead())
111 throw new RuntimeException(
"Cant open JNI file: "+resource.getAbsolutePath());
113 System.load(resource.getAbsolutePath());
116 public static void copyResource(InputStream io, File file)
throws IOException {
117 FileOutputStream fos =
new FileOutputStream(file);
120 byte[] buf =
new byte[256];
122 while ((read = io.read(buf)) > 0) {
123 fos.write(buf, 0, read);
130 String tmpDir = System.getProperty(
"java.io.tmpdir");
132 if ((tmpDir ==
null) || (tmpDir.length() == 0)) {
136 String displayName =
new File(fileName).getName().split(
"\\.")[0];
138 String user = System.getProperty(
"user.name");
143 for(
int i = 0; i < 10; i++) {
144 dir =
new File(tmpDir, displayName +
"_" + user +
"_" + (i));
146 if (!dir.isDirectory()) {
151 File[] files = dir.listFiles();
152 for (
int j = 0; j < files.length; j++) {
153 if (!files[j].
delete()) {
157 }
catch (Throwable e) {
162 if ((!dir.exists()) && (!dir.mkdirs())) {
168 }
catch (Throwable e) {
173 if ((fd.exists()) && (!fd.delete())) {
178 if (!fd.createNewFile()) {
181 }
catch (IOException e) {
183 }
catch (Throwable e) {
190 if(fd ==
null || !fd.canRead()) {
214 return getOsName().toLowerCase().startsWith(
"windows") ||
getOsName().toLowerCase().startsWith(
"microsoft") ||
getOsName().toLowerCase().startsWith(
"ms");
218 return getOsName().toLowerCase().startsWith(
"linux");
222 return getOsName().toLowerCase().startsWith(
"mac");
230 return System.getProperty(
"os.name");
234 return System.getProperty(
"os.arch");
237 @SuppressWarnings(
"unused")
void inJarLoad(String name)
static String getExtension()
static boolean isCortexA8()
synchronized void load(String libraryName)
static String getOsName()
static String getIdentifier()
static void copyResource(InputStream io, File file)
static File inJarLoad(InputStream inputStream, String name)
static String getOsArch()
void loadLib(String name)
InputStream locateResource(String name)
static File prepResourceLocation(String fileName)
void loadResource(File resource)
static boolean isWindows()