Exemplo n.º 1
0
 /**
  * Returns the next unsigned byte (see {@link InputStream#read}. {@code -1} is returned if all
  * bytes have been read.
  *
  * @return next unsigned byte
  * @throws IOException I/O exception
  */
 protected int next() throws IOException {
   final int blen = buffer.length;
   final byte[] buf = buffer;
   if (bpos >= bsize) {
     if (bsize == 0 || bsize == blen) {
       // reset mark if buffer is full
       if (bsize == blen) bmark = -1;
       // buffer is empty or full: re-fill it
       bsize = 0;
       bpos = 0;
     }
     int r;
     while ((r = in.read(buf, bsize, blen - bsize)) == 0) ;
     if (r < 0) return -1;
     bsize += r;
     read += r;
   }
   return buf[bpos++] & 0xFF;
 }
Exemplo n.º 2
0
    @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();
      }
    }