Archived
0

Обновление API: метод SaveResource

Данный метод позволяет сохранить внутренние ресурсы модуля в файловую систему. Проще говоря: выгрузить встроенный файл.
This commit is contained in:
2016-08-16 15:12:24 +03:00
parent cd84b915b3
commit 0d717e086c
2 changed files with 18 additions and 1 deletions

View File

@@ -19,7 +19,7 @@
<groupId>asys</groupId> <groupId>asys</groupId>
<artifactId>api</artifactId> <artifactId>api</artifactId>
<version>0.7</version> <version>0.8</version>
<packaging>bundle</packaging> <packaging>bundle</packaging>
<dependencies> <dependencies>

View File

@@ -7,6 +7,10 @@ package asys.api;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration; import org.osgi.framework.ServiceRegistration;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Dictionary; import java.util.Dictionary;
import java.util.Hashtable; import java.util.Hashtable;
@@ -39,6 +43,19 @@ public class ASysUtils {
System.out.printf(format+"\n", objects); System.out.printf(format+"\n", objects);
} }
public static void SaveResource(String resource, File saveTo) throws IOException {
InputStream stream = ASysUtils.class.getResourceAsStream(resource);
FileOutputStream fos = new FileOutputStream(saveTo);
byte[] buff = new byte[65536];
int len;
while ((len = stream.read(buff)) > 0) {
fos.write(buff, 0, len);
}
fos.flush();
fos.close();
stream.close();
}
private static Dictionary<String, Object> getCommandListByAnnotationMethods(String scope, Class<?> clazz) { private static Dictionary<String, Object> getCommandListByAnnotationMethods(String scope, Class<?> clazz) {
List<String> listCommand = new Vector<>(); List<String> listCommand = new Vector<>();