private void parseItemIdList(Reader in, IItemIdListHandler handler)
      throws JsonParseException, IOException, RemoteException {
    JsonFactory f = new JsonFactory();
    JsonParser jp = f.createParser(in);

    String currName;

    List<String> idList = new ArrayList<String>();

    jp.nextToken(); // will return JsonToken.START_OBJECT (verify?)
    while (jp.nextToken() != JsonToken.END_OBJECT) {
      currName = jp.getCurrentName();
      jp.nextToken(); // move to value, or START_OBJECT/START_ARRAY
      if (currName.equals("itemRefs")) { // contains an object
        // start items
        while (jp.nextToken() != JsonToken.END_ARRAY) {
          currName = jp.getCurrentName();
          if (currName == null) continue;
          jp.nextToken();
          if (currName.equals("id")) {
            idList.add(Utils.dec2Hex(jp.getText())); // convert dec to hex
          } else {
            jp.skipChildren();
          }
        }

        handler.items(idList);

      } else {
        jp.skipChildren();
      }
    }
  }
Beispiel #2
0
  // NOTE: /api/0/stream/items/ids
  private Reader readStreamItemIds(long syncTime, IItemIdListHandler handler)
      throws IOException, ReaderException, RemoteException {
    initAuth();

    StringBuilder buff = new StringBuilder(URL_API_STREAM_ITEM_IDS.length() + 128);
    buff.append(URL_API_STREAM_ITEM_IDS);
    buff.append("?output=json"); // xml or json
    String uid = handler.stream();
    if (uid != null) {
      buff.append("&s=");
      buff.append(Utils.encode(uid));
    }
    if (handler.excludeRead()) {
      buff.append("&xt=").append(STATE_GOOGLE_READ);
    }
    int limit = handler.limit();
    if (limit > 0) {
      buff.append("&n=").append(limit);
    }
    buff.append("&r=").append(handler.newestFirst() ? "n" : "o");

    return doGetReader(buff.toString());
  }