1 | static ThreadLocal<Map<S, L<S>>> loadBinaryPage_responseHeaders = new ThreadLocal; |
2 | static ThreadLocal<SS> loadBinaryPage_extraHeaders = new ThreadLocal; |
3 | |
4 | static byte[] loadBinaryPage(String url) ctex {
|
5 | print("Loading " + url);
|
6 | return loadBinaryPage(loadPage_openConnection(new URL(url))); |
7 | } |
8 | |
9 | static byte[] loadBinaryPage(URLConnection con) ctex {
|
10 | SS extraHeaders = getAndClearThreadLocal(loadBinaryPage_extraHeaders); |
11 | setHeaders(con); |
12 | for (S key : keys(extraHeaders)) |
13 | con.setRequestProperty(key, extraHeaders.get(key)); |
14 | ret loadBinaryPage_noHeaders(con); |
15 | } |
16 | |
17 | static byte[] loadBinaryPage_noHeaders(URLConnection con) ctex {
|
18 | ByteArrayOutputStream buf = new ByteArrayOutputStream(); |
19 | InputStream inputStream = con.getInputStream(); |
20 | loadBinaryPage_responseHeaders.set(con.getHeaderFields()); |
21 | long len = 0; |
22 | try { len = con.getContentLength/*Long*/(); } catch (Throwable e) { printStackTrace(e); }
|
23 | int n = 0; |
24 | while (true) {
|
25 | int ch = inputStream.read(); |
26 | if (ch < 0) |
27 | break; |
28 | buf.write(ch); |
29 | if (++n % 100000 == 0) |
30 | println(" " + n + (len != 0 ? "/" + len : "") + " bytes loaded.");
|
31 | } |
32 | inputStream.close(); |
33 | return buf.toByteArray(); |
34 | } |
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: | 1115 / 4257 |
| Version history: | 9 change(s) |
| Referenced in: | [show references] |