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

28
LINES

< > BotCompany Repo | #1008030 // loadBinaryPageToFile

JavaX fragment (include)

static void loadBinaryPageToFile(S url, File file) ctex {
  print("Loading " + url);
  loadBinaryPageToFile(openConnection(new URL(url)), file);
}

static void loadBinaryPageToFile(URLConnection con, File file) ctex {
  setHeaders(con);
  loadBinaryPageToFile_noHeaders(con, file);
}

static void loadBinaryPageToFile_noHeaders(URLConnection con, File file) ctex {
  assertNotNull(file);
  File ftemp = new File(f2s(file) + "_temp");
  FileOutputStream buf = newFileOutputStream(mkdirsFor(ftemp));
  try {
    InputStream inputStream = con.getInputStream();
    long len = 0;
    try { len = con.getContentLength/*Long*/(); } catch (Throwable e) { printStackTrace(e); }
    S pat = "  {*}" + (len != 0 ? "/" + len : "") + " bytes loaded.";
    copyStreamWithPrints(inputStream, buf, pat);
    inputStream.close();
    buf.close();
    file.delete();
    renameFile_assertTrue(ftemp, file);
  } finally {
    if (buf != null) buf.close();
  }
}

Author comment

Began life as a copy of #1000837

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1008030
Snippet name: loadBinaryPageToFile
Eternal ID of this version: #1008030/13
Text MD5: 64b4f613fe7d884bab75b500175bcbc2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-25 22:22:49
Source code size: 972 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 551 / 644
Version history: 12 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1033018 - httpInputStream