official tutorial code为:
List<? extends SwiftObject> objs = os.objectStorage().objects().list(containerName);但这有明确的10000个文件的限制。有没有更常用的方法来列出更大的容器?
发布于 2018-01-16 00:20:37
好的,我自己做的,根据测试结果似乎是正确的。适当的API按名称(文档中有记录)和帐户“名称标记”对结果进行排序,“名称标记”指示列表的起始点。
final List<String> result = new ArrayList<>();
final ObjectStorageObjectService oservice = os.objectStorage().objects();
final ObjectListOptions listOptions = ObjectListOptions.create().limit(LIST_PAGE_LIMIT);
List<? extends SwiftObject> objects;
do {
// Get next list page.
objects = oservice.list(CONTAINER_NAME, listOptions);
// If we have some result setup next page.
if (!objects.isEmpty()) {
listOptions.marker(objects.get(objects.size() - 1).getName());
}
if (LOG.isDebugEnabled()) {
LOG.debug("SWIFT OS: listed page of {} file(s).", objects.size());
}
// Add current results page to the end.
for (final SwiftObject swiftObject : objects) {
fileList.add(swiftObject.getName());
}
// Process will be repeated unless we have incomplete page.
} while (objects.size() >= LIST_PAGE_LIMIT);https://stackoverflow.com/questions/48265918
复制相似问题