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

36
LINES

< > BotCompany Repo | #1009523 // loadPage_noClose - DON'T USE

JavaX fragment (include)

please include function loadPage.

static S loadPage_noClose(URLConnection con, URL url) throws IOException {
  try {
    if (!loadPage_anonymous)
      setHeaders(con);
    if (loadPage_allowGzip)
      con.setRequestProperty("Accept-Encoding", "gzip");
  } catch (Throwable e) {} // fails if within doPost
  String contentType = con.getContentType();
  if (contentType == null)
    throw new IOException("Page could not be read: " + url);
  //print("Content-Type: " + contentType);
  String charset = loadPage_charset == null ? null : loadPage_charset.get();
  if (charset == null) charset = loadPage_guessCharset(contentType);
  
  InputStream in = con.getInputStream();
  if ("gzip".equals(con.getContentEncoding())) {
    if (loadPage_debug)
      print("loadPage: Using gzip.");
    in = new GZIPInputStream(in);
  }
  Reader r = new InputStreamReader(in, charset);
  
  StringBuilder buf = new StringBuilder();
  int n = 0;
  while (true) {
    int ch = r.read();
    if (ch < 0)
      break;
    buf.append((char) ch);
    ++n;
    if ((n % loadPage_verboseness) == 0) print("  " + n + " chars read");
  }
  return buf.toString();
}

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: 324 / 355
Version history: 1 change(s)
Referenced in: [show references]