Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > BotCompany Repo | #1004188 // readFileFromPhone - should also work with remote PCs

JavaX fragment (include)

1  
static int readFileFromPhone_chunkSize = 500000; // see #1004128
2  
3  
static byte[] readFileFromPhone(S path) {
4  
  ret readFileFromPhone(gateway(), path);
5  
}
6  
7  
static byte[] readFileFromPhone(S ip, S path) {
8  
  // todo: rough
9  
  DialogIO io;
10  
  talkTo_byThread.set(litmap(ip + ":" + 4999, io = talkTo(ip, 4999)));
11  
  io.noClose = true;
12  
  try {
13  
    long n = parseLong(sendToAwareness(ip, "get file * length", path));
14  
    if (n != (int) n) fail("Too big to load " + quote(path) + " in memory!! " + n);
15  
    int l = (int) n;
16  
    byte[] data = new byte[l];
17  
    for (int i = 0; i < l;) {
18  
      print("[Loading file from phone, " + i + "/" + l + "]");
19  
      int len = min(readFileFromPhone_chunkSize, l-i);
20  
      new Matches m;
21  
      S answer = sendToAwarenessSilently(ip, "load file * bin from * l *", path, i, len);
22  
      assertTrue(answer, answer.startsWith("OK "));
23  
      System.arraycopy(bytesFromHex(answer.substring(3)), 0, data, i, len);
24  
      i += len;
25  
    }
26  
    ret data;
27  
  } finally {
28  
    io.noClose = false;
29  
    io.close();
30  
    talkTo_byThread.set(null);
31  
  }
32  
}

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: #1004188
Snippet name: readFileFromPhone - should also work with remote PCs
Eternal ID of this version: #1004188/1
Text MD5: 3fbfbf27764595a95878138c26382fbb
Author: stefan
Category: javax / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-01-12 03:18:00
Source code size: 1085 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 552 / 537
Referenced in: [show references]