57 lines
1.1 KiB
Java
57 lines
1.1 KiB
Java
package org.hwo.platform;
|
|
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
|
|
import org.hwo.platform.natives.NativeLoader;
|
|
|
|
public class Ressource {
|
|
|
|
public static boolean extract(Class<?> clazz,String resource,String filename){
|
|
return extract(
|
|
clazz.getResourceAsStream(resource),
|
|
filename
|
|
);
|
|
}
|
|
|
|
public static boolean extract(String resource,String filename){
|
|
return extract(
|
|
NativeLoader.class.getResourceAsStream(resource),
|
|
filename
|
|
);
|
|
}
|
|
|
|
public static byte[] load(String resource){
|
|
try {
|
|
return load(NativeLoader.class.getResourceAsStream(resource));
|
|
} catch (IOException ioe){
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static byte[] load(InputStream in) throws IOException{
|
|
if (in == null){
|
|
return new byte[0];
|
|
}
|
|
byte[] buffer = new byte[in.available()];
|
|
in.read(buffer);
|
|
return buffer;
|
|
}
|
|
|
|
private static boolean extract(InputStream in,String filename){
|
|
try {
|
|
FileOutputStream fos = new FileOutputStream(filename);
|
|
fos.write(load(in));
|
|
fos.close();
|
|
|
|
return true;
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
|
|
}
|