1 | static int copyFileToPhone_chunkSize = 500000; // see #1004128 |
2 | |
3 | static void copyFileToPhone(S localPath, S destPath, bool withContinue) { |
4 | copyFileToPhone(new File(localPath), destPath, withContinue); |
5 | } |
6 | |
7 | static void copyFileToPhone(File f, S destPath, bool withContinue) { |
8 | if (!f.isFile()) fail("Not a file: " + f2s(f)); |
9 | if (destPath.endsWith("/")) destPath += f.getName(); |
10 | |
11 | long i = 0; |
12 | long len = f.length(); |
13 | DialogIO io = talkTo(gateway(), 4999); |
14 | try { |
15 | if (withContinue) { |
16 | i = parseLong(io.askLoudly(forward("Awareness", "get file * length", destPath))); |
17 | if (i == len) { print("File fully copied"); ret; } |
18 | } |
19 | if (i == 0) |
20 | io.askLoudly(forward("Awareness", "delete file *", destPath)); |
21 | for (; i < len; i += copyFileToPhone_chunkSize) { |
22 | print("[Copying file to phone, " + i + "/" + len + "]"); |
23 | long j = min(len, i+copyFileToPhone_chunkSize); |
24 | byte[] data = loadBinaryFileChunk(f, i, toInt(j-i)); |
25 | S answer = io.ask(forward("Awareness", "write file * bin from * data *", |
26 | destPath, i, bytesToHex(data))); |
27 | assertTrue(answer, match("OK", answer)); |
28 | } |
29 | } finally { |
30 | io.close(); |
31 | } |
32 | } |
Began life as a copy of #1004188
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005201 |
Snippet name: | copyFileToPhone |
Eternal ID of this version: | #1005201/1 |
Text MD5: | 2ba401fd21cb1e9ef9b8bdb592aa6bfc |
Author: | stefan |
Category: | javax / networking |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-10-22 03:24:05 |
Source code size: | 1199 bytes / 32 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 565 / 539 |
Referenced in: | [show references] |