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

34
LINES

< > BotCompany Repo | #1000837 // loadBinaryPage current

JavaX fragment (include)

static ThreadLocal<Map<S, L<S>>> loadBinaryPage_responseHeaders = new ThreadLocal;
static ThreadLocal<SS> loadBinaryPage_extraHeaders = new ThreadLocal;

static byte[] loadBinaryPage(String url) ctex {
  print("Loading " + url);
  return loadBinaryPage(loadPage_openConnection(new URL(url)));
}

static byte[] loadBinaryPage(URLConnection con) ctex {
  SS extraHeaders = getAndClearThreadLocal(loadBinaryPage_extraHeaders);
  setHeaders(con);
  for (S key : keys(extraHeaders))
    con.setRequestProperty(key, extraHeaders.get(key));
  ret loadBinaryPage_noHeaders(con);
}

static byte[] loadBinaryPage_noHeaders(URLConnection con) ctex {
  ByteArrayOutputStream buf = new ByteArrayOutputStream();
  InputStream inputStream = con.getInputStream();
  loadBinaryPage_responseHeaders.set(con.getHeaderFields());
  long len = 0;
  try { len = con.getContentLength/*Long*/(); } catch (Throwable e) { printStackTrace(e); }
int n = 0;
  while (true) {
    int ch = inputStream.read();
    if (ch < 0)
      break;
    buf.write(ch);
    if (++n % 100000 == 0)
      println("  " + n + (len != 0 ? "/" + len : "") + " bytes loaded.");
  }
  inputStream.close();
  return buf.toByteArray();
}

Author comment

Began life as a copy of #2000466

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000837
Snippet name: loadBinaryPage current
Eternal ID of this version: #1000837/10
Text MD5: 5c6dd64f2b9d51cf7c4bdd7b21f78ffb
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-04 17:35:47
Source code size: 1218 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 785 / 3915
Version history: 9 change(s)
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1008030 - loadBinaryPageToFile
#1008548 - loadBinaryPageSilently
#1013954 - loadBinaryPageWithRedirects
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)