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

44
LINES

< > BotCompany Repo | #1000345 // loadDataSnippet (developing)

JavaX source code - run with: x30.jar

1  
!636
2  
!standard functions
3  
4  
main {
5  
  psvm {
6  
    File file = loadDataSnippet("#1000304"); // jar file (1.x MB)
7  
    System.out.println(file);
8  
    System.out.println("  " + file.length());
9  
  }
10  
  
11  
  static File loadDataSnippet(String snippetID) throws IOException {
12  
    File libraryFile = DiskSnippetCache_getLibrary(parseSnippetID(snippetID));
13  
    if (libraryFile == null) {
14  
      byte[] data = loadDataSnippetImpl(snippetID);
15  
      DiskSnippetCache_putLibrary(parseSnippetID(snippetID), data);
16  
      libraryFile = DiskSnippetCache_getLibrary(parseSnippetID(snippetID));
17  
    }
18  
    return libraryFile;
19  
  }
20  
21  
  static byte[] loadDataSnippetImpl(String snippetID) throws IOException {
22  
    byte[] data;
23  
    try {
24  
      URL url = new URL("http://eyeocr.sourceforge.net/filestore/filestore.php?cmd=serve&file=blob_"
25  
        + parseSnippetID(snippetID) + "&contentType=application/binary");
26  
      System.err.println("Loading library: " + url);
27  
      data = loadBinaryPage(url.openConnection());
28  
    } catch (FileNotFoundException e) {
29  
      throw new IOException("Binary snippet #" + snippetID + " not found or not public");
30  
    }
31  
    return data;
32  
  }
33  
34  
  public static synchronized File DiskSnippetCache_getLibrary(long snippetID) throws IOException {
35  
    initSnippetCache();
36  
    File file = new File(DiskSnippetCache_dir, "data_" + snippetID + ".jar");
37  
    return file.exists() ? file : null;
38  
  }
39  
40  
  public static synchronized void DiskSnippetCache_putLibrary(long snippetID, byte[] data) throws IOException {
41  
    initSnippetCache();
42  
    saveBinaryFile(new File(DiskSnippetCache_dir, "data_" + snippetID).getPath() + ".jar", data);
43  
  }
44  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000345
Snippet name: loadDataSnippet (developing)
Eternal ID of this version: #1000345/1
Text MD5: 97b7c6d0b07f22f9a4955049bdee0461
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-07-26 20:29:53
Source code size: 1668 bytes / 44 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 698 / 541
Referenced in: [show references]