@Override public HTTPResponse call() throws Exception { final HttpURLConnection hc = (HttpURLConnection) uri.toURL().openConnection(); hc.setReadTimeout(SOCKET_TIMEOUT); try { while (!stop) { try { final int code = hc.getResponseCode(); final InputStream input = hc.getInputStream(); final ByteList bl = new ByteList(); for (int i; (i = input.read()) != -1; ) bl.add(i); return new HTTPResponse(code, bl.toString()); } catch (final SocketTimeoutException e) { } } return null; } finally { hc.disconnect(); } }
/** * Reads a string from the input stream, suffixed by a {@code 0} byte. * * @return string * @throws IOException I/O Exception */ public final String readString() throws IOException { final ByteList bl = new ByteList(); for (int l; (l = next()) > 0; ) bl.add(l); return bl.toString(); }