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

28
LINES

< > TinyBrain | #1000837 - loadBinaryPage current

JavaX fragment (include)

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

static byte[] loadBinaryPage(URLConnection con) ctex {
  setHeaders(con);
  ret loadBinaryPage_noHeaders(con);
}

static byte[] loadBinaryPage_noHeaders(URLConnection con) ctex {
  ByteArrayOutputStream buf = new ByteArrayOutputStream();
  InputStream inputStream = con.getInputStream();
  long len = 0;
  try { len = con.getContentLengthLong(); } 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   

Travelled to 2 computer(s): cfunsshuasjs, onxytkatvevr

No comments. add comment

Snippet ID: #1000837
Snippet name: loadBinaryPage current
Eternal ID of this version: #1000837/5
Text MD5: 993f5087aca27c46eba82c6b7eb647ac
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-21 01:04:37
Source code size: 822 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 126 / 2933
Version history: 4 change(s)
Referenced in: [show]