Exemplo n.º 1
1
  @Override
  public void handleItemList(IItemListHandler handler, long syncTime)
      throws IOException, ReaderException {
    // http://www.google.com/reader/api/0/stream/contents/user%2F-%2Fstate%2Fcom.google%2Fread?client=newsplus&output=json&ck=1276066665822&n=20&r=n
    Reader in = null;
    try {
      long startTime = handler.startTime();
      in = readStreamContents(syncTime, startTime, handler, null);

      String continuation = parseItemList(in, handler);

      int limit = handler.limit();
      int max = limit > SYNC_MAX_ITEMS ? SYNC_MAX_ITEMS : limit;
      int count = 1; // continuation count
      while ((limit == 0 || limit > max * count)
          && handler.continuation()
          && continuation != null
          && continuation.length() > 0) {
        in.close();
        in = readStreamContents(syncTime, startTime, handler, continuation);
        continuation = parseItemList(in, handler);
        count++;
      }
    } catch (JsonParseException e) {
      e.printStackTrace();
      throw new ReaderException("data parse error", e);
    } catch (RemoteException e) {
      e.printStackTrace();
      throw new ReaderException("remote connection error", e);
    } finally {
      if (in != null) in.close(); // ensure resources get cleaned up timely
    }
  }
Exemplo n.º 2
0
  // NOTE: /api/0/stream/contents
  private Reader readStreamContents(
      long syncTime, long startTime, IItemListHandler handler, String continuation)
      throws IOException, ReaderException, RemoteException {
    initAuth();

    StringBuilder buff = new StringBuilder(URL_API_STREAM_CONTENTS.length() + 128);
    buff.append(URL_API_STREAM_CONTENTS);
    String stream = handler.stream();
    if (stream != null) {
      if (stream.equals(STATE_READING_LIST)) stream = STATE_GOOGLE_READING_LIST;
      else if (stream.equals(STATE_STARRED)) stream = STATE_GOOGLE_STARRED;
      buff.append("/").append(Utils.encode(stream));
    }
    buff.append("?client=newsplus&ck=").append(syncTime);
    if (handler.excludeRead()) {
      buff.append("&xt=").append(STATE_GOOGLE_READ);
    }
    if (continuation != null && continuation.length() > 0) {
      buff.append("&c=").append(continuation);
    }
    if (startTime > 0) {
      buff.append("&ot=").append(startTime);
    }
    int limit = handler.limit();
    limit = (limit > SYNC_MAX_ITEMS || limit == 0) ? SYNC_MAX_ITEMS : limit;
    if (limit > 0) {
      // google only allows max 1000 at once
      buff.append("&n=").append(limit > SYNC_MAX_ITEMS ? SYNC_MAX_ITEMS : limit);
    }
    buff.append("&r=").append(handler.newestFirst() ? "n" : "o");

    return doGetReader(buff.toString());
  }