Archived
0

fix API: изменение работы метода SaveResource

This commit is contained in:
2016-08-16 16:52:51 +03:00
parent e35dfe2b7b
commit fd37e98dfb
2 changed files with 7 additions and 5 deletions

View File

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

View File

@@ -43,17 +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 { public static void SaveResource(InputStream resourceAsStream, File saveTo) throws IOException {
InputStream stream = ASysUtils.class.getResourceAsStream(resource); if (resourceAsStream == null) {
throw new NullPointerException("Resource not found! (stream == null)");
}
FileOutputStream fos = new FileOutputStream(saveTo); FileOutputStream fos = new FileOutputStream(saveTo);
byte[] buff = new byte[65536]; byte[] buff = new byte[65536];
int len; int len;
while ((len = stream.read(buff)) > 0) { while ((len = resourceAsStream.read(buff)) > 0) {
fos.write(buff, 0, len); fos.write(buff, 0, len);
} }
fos.flush(); fos.flush();
fos.close(); fos.close();
stream.close(); resourceAsStream.close();
} }
private static Dictionary<String, Object> getCommandListByAnnotationMethods(String scope, Class<?> clazz) { private static Dictionary<String, Object> getCommandListByAnnotationMethods(String scope, Class<?> clazz) {