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