String result;
try {
result = serviceResponse
.getResponseBodyAsString(Constants.ENCODING);
} catch (Exception e) {
throw new ServerDataException("Failed to get response from " + url);
}
LOG.debug("User friends ids : " + result);
try {
JSONObject jobj = new JSONObject(result);
if (jobj.has("ids")) {
JSONArray idList = jobj.getJSONArray("ids");
int flength = idList.length();
int ids[] = new int[flength];
for (int i = 0; i < idList.length(); i++) {
ids[i] = idList.getInt(i);
}
if (flength > 0) {
if (flength > 100) {
int i = flength / 100;
int temparr[];
for (int j = 1; j <= i; j++) {
temparr = new int[100];
for (int k = (j - 1) * 100, c = 0; k < j * 100; k++, c++) {
temparr[c] = ids[k];
}
plist.addAll(lookupUsers(temparr));
}
if (flength > i * 100) {
temparr = new int[flength - i * 100];
for (int k = i * 100, c = 0; k < flength; k++, c++) {
temparr[c] = ids[k];
}
plist.addAll(lookupUsers(temparr));
}
} else {
plist.addAll(lookupUsers(ids));
}
}
}
} catch (Exception e) {
throw new ServerDataException(
"Failed to parse the user friends json : " + result, e);
}
return plist;
}