By the way, when I say slow, I mean it takes almost 1 second to get each ItemInfo:
for (BoxItem.Info itemInfo : targetFolder) {
if (itemInfo instanceof BoxFolder.Info) {
...
etc.
Ok, I finally figured out why it is so slow: By default, the method gets only one Box.FileInfo object at a time from the server. To speed up you need to use pagination with max limit of 100. Something like the following:
int offset = 0; //Start
int pageSize = 100;
while (true) {
Collection itemsInFolder = targetFolder.getChildrenRange(offset, pageSize, "name", "size");
for (BoxItem.Info itemInfo : itemsInFolder) {
if (itemInfo instanceof BoxFile.Info) {
....
}
else if (itemInfo instanceof BoxFolder.Info) {
...
}
}
if (itemsInFolder.size() < pageSize) break; //Less than max returned signals end
offset += pageSize;
}