static int copyFileToPhone_chunkSize = 500000; // see #1004128 static void copyFileToPhone(S localPath, S destPath, bool withContinue) { copyFileToPhone(new File(localPath), destPath, withContinue); } static void copyFileToPhone(File f, S destPath, bool withContinue) { if (!f.isFile()) fail("Not a file: " + f2s(f)); if (destPath.endsWith("/")) destPath += f.getName(); long i = 0; long len = f.length(); DialogIO io = talkTo(gateway(), 4999); try { if (withContinue) { i = parseLong(io.askLoudly(forward("Awareness", "get file * length", destPath))); if (i == len) { print("File fully copied"); ret; } } if (i == 0) io.askLoudly(forward("Awareness", "delete file *", destPath)); for (; i < len; i += copyFileToPhone_chunkSize) { print("[Copying file to phone, " + i + "/" + len + "]"); long j = min(len, i+copyFileToPhone_chunkSize); byte[] data = loadBinaryFileChunk(f, i, toInt(j-i)); S answer = io.ask(forward("Awareness", "write file * bin from * data *", destPath, i, bytesToHex(data))); assertTrue(answer, match("OK", answer)); } } finally { io.close(); } }
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: | 562 / 534 |
Referenced in: | [show references] |