|
4 | 4 | import iotaFlashWrapper.Model.*;
|
5 | 5 |
|
6 | 6 |
|
| 7 | +import java.io.File; |
| 8 | +import java.io.FileInputStream; |
7 | 9 | import java.io.IOException;
|
| 10 | +import java.net.URL; |
8 | 11 | import java.nio.charset.Charset;
|
9 | 12 | import java.nio.file.Files;
|
10 | 13 | import java.nio.file.Paths;
|
11 | 14 | import java.util.ArrayList;
|
12 | 15 | import java.util.List;
|
13 | 16 | import java.util.Map;
|
14 | 17 |
|
| 18 | +import static java.nio.file.Files.readAllBytes; |
| 19 | + |
15 | 20 | public class IotaFlashBridge {
|
16 |
| - private static String iotaLibPath = "res/iota.flash.js"; |
17 |
| - private static String iotaHelperLibPath = "res/iota.flash.helper.js"; |
| 21 | + private static String iotaLibPath = "iota.flash.js"; |
| 22 | + private static String iotaHelperLibPath = "iota.flash.helper.js"; |
18 | 23 | private static V8 engine;
|
19 | 24 | private static V8Object transfer;
|
20 | 25 | private static V8Object multisig;
|
@@ -301,13 +306,13 @@ public static FlashObject applyTransfersToUser(UserObject user, ArrayList<Bundle
|
301 | 306 | static String readFile(String path, Charset encoding)
|
302 | 307 | throws IOException
|
303 | 308 | {
|
304 |
| - byte[] encoded; |
305 |
| - try { |
306 |
| - encoded = Files.readAllBytes(Paths.get(path)); |
307 |
| - } catch (IOException error) { |
308 |
| - System.out.println("Failed to load file: " + error.getLocalizedMessage()); |
309 |
| - return ""; |
310 |
| - } |
311 |
| - return new String(encoded, encoding); |
| 309 | + URL url = IotaFlashBridge.class.getClassLoader().getResource(path); |
| 310 | + File file = new File(url.getPath()); |
| 311 | + FileInputStream fis = new FileInputStream(file); |
| 312 | + byte[] data = new byte[(int) file.length()]; |
| 313 | + fis.read(data); |
| 314 | + fis.close(); |
| 315 | + |
| 316 | + return new String(data, "UTF-8"); |
312 | 317 | }
|
313 | 318 | }
|
0 commit comments