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)

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);
  }
}

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: 551 / 536
Referenced in: #1005201 - copyFileToPhone
#1006654 - Standard functions list 2 (LIVE, continuation of #761)