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

40
LINES

< > BotCompany Repo | #1008031 // loadDataSnippetToFile - TODO: what's the difference to loadBinarySnippet?

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4344L/29K).

static File loadDataSnippetToFile(S snippetID) ctex {
  ifndef NoResourceLoader
  IResourceLoader rl = vm_getResourceLoader();
  if (rl != null)
    ret rl.loadLibrary(snippetID);
  endifndef
  
  ret loadDataSnippetToFile_noResourceLoader(snippetID);
}
  
static File loadDataSnippetToFile_noResourceLoader(S snippetID) ctex {
  snippetID = fsI(snippetID);
  
  File f = DiskSnippetCache_file(parseSnippetID(snippetID));
  new L<URL> urlsTried;
  new L<Throwable> errors;
  try {
    URL url = addAndReturn(urlsTried, new URL(dataSnippetLink(snippetID)));
    print("Loading library: " + hideCredentials(url));
    try {
      loadBinaryPageToFile(openConnection(url), f);
      if (fileSize(f) == 0) fail();
    } catch e {
      errors.add(e);
      url = addAndReturn(urlsTried, new URL(tb_mainServer() + "/blobs/" + psI(snippetID)));
      print(e);
      print("Trying other server: " + hideCredentials(url));
      loadBinaryPageToFile(openConnection(url), f);
      print("Got bytes: " + fileSize(f));
    }
    // TODO: check if we hit the "LOADING" message
    if (fileSize(f) == 0) fail();
    System.err.println("Bytes loaded: " + fileSize(f));
  } catch e {
    //printStackTrace(e);
    errors.add(e);
    fail("Binary snippet " + snippetID + " not found or not public. URLs tried: " + allToString(urlsTried) + ", errors: " + allToString(errors));
  }
  return f;
}

Author comment

Began life as a copy of #1000675

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1008031
Snippet name: loadDataSnippetToFile - TODO: what's the difference to loadBinarySnippet?
Eternal ID of this version: #1008031/31
Text MD5: 2e05f36d888f39877c910f4849ba1f61
Transpilation MD5: c4ec7b62c160f2e0eeca83facedf82d7
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-10-14 16:01:48
Source code size: 1418 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 607 / 705
Version history: 30 change(s)
Referenced in: [show references]