static ThreadLocal>> loadBinaryPage_responseHeaders = new ThreadLocal; static ThreadLocal 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(); }