1 | please include function loadPage. |
2 | |
3 | static S loadPage_noClose(URLConnection con, URL url) throws IOException {
|
4 | try {
|
5 | if (!loadPage_anonymous) |
6 | setHeaders(con); |
7 | if (loadPage_allowGzip) |
8 | con.setRequestProperty("Accept-Encoding", "gzip");
|
9 | } catch (Throwable e) {} // fails if within doPost
|
10 | String contentType = con.getContentType(); |
11 | if (contentType == null) |
12 | throw new IOException("Page could not be read: " + url);
|
13 | //print("Content-Type: " + contentType);
|
14 | String charset = loadPage_charset == null ? null : loadPage_charset.get(); |
15 | if (charset == null) charset = loadPage_guessCharset(contentType); |
16 | |
17 | InputStream in = con.getInputStream(); |
18 | if ("gzip".equals(con.getContentEncoding())) {
|
19 | if (loadPage_debug) |
20 | print("loadPage: Using gzip.");
|
21 | in = new GZIPInputStream(in); |
22 | } |
23 | Reader r = new InputStreamReader(in, charset); |
24 | |
25 | StringBuilder buf = new StringBuilder(); |
26 | int n = 0; |
27 | while (true) {
|
28 | int ch = r.read(); |
29 | if (ch < 0) |
30 | break; |
31 | buf.append((char) ch); |
32 | ++n; |
33 | if ((n % loadPage_verboseness) == 0) print(" " + n + " chars read");
|
34 | } |
35 | return buf.toString(); |
36 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1009523 |
| Snippet name: | loadPage_noClose - DON'T USE |
| Eternal ID of this version: | #1009523/2 |
| Text MD5: | 343d16db83b96273ac188193ff63acef |
| Author: | stefan |
| Category: | javax / networking |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-08-06 19:28:27 |
| Source code size: | 1177 bytes / 36 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 604 / 642 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |