static int readFileFromPhone_chunkSize = 500000; // see #1004128 static byte[] readFileFromPhone(S path) { ret readFileFromPhone(gateway(), path); } static byte[] readFileFromPhone(S ip, S path) { // todo: rough DialogIO io; talkTo_byThread.set(litmap(ip + ":" + 4999, io = talkTo(ip, 4999))); io.noClose = true; try { long n = parseLong(sendToAwareness(ip, "get file * length", path)); if (n != (int) n) fail("Too big to load " + quote(path) + " in memory!! " + n); int l = (int) n; byte[] data = new byte[l]; for (int i = 0; i < l;) { print("[Loading file from phone, " + i + "/" + l + "]"); int len = min(readFileFromPhone_chunkSize, l-i); new Matches m; S answer = sendToAwarenessSilently(ip, "load file * bin from * l *", path, i, len); assertTrue(answer, answer.startsWith("OK ")); System.arraycopy(bytesFromHex(answer.substring(3)), 0, data, i, len); i += len; } ret data; } finally { io.noClose = false; io.close(); talkTo_byThread.set(null); } }