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

28
LINES

< > TinyBrain | #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 {
  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   

Travelled to 4 computer(s): cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1008030
Snippet name: loadBinaryPageToFile
Eternal ID of this version: #1008030/12
Text MD5: 803a809de9b20b05ce7de855bda55943
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-04 17:35:32
Source code size: 948 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 122 / 134
Version history: 11 change(s)
Referenced in: [show]