[英]How to retrieve a segmented List of Containers using the new Java v12 SDK for Azure Blob Storage?
I see that the .NET examples have a ListContainersSegmented API call.我看到 .NET 示例有一个ListContainersSegmented API 调用。
The Java SDK documentation specifies a listBlobContainers call but there is no mention about when it hits the limit of containers it will return per call. Java SDK 文档指定了一个listBlobContainers调用,但没有提及它何时达到每次调用将返回的容器限制。 Is there a different way to obtain the NextMarker or ContinuationToken for this call?
是否有其他方法可以获取此调用的NextMarker或ContinuationToken ?
When we use the method listBlobContainers
to list containers, It will paginate if its number is greater than 5000. We also can use ListBlobContainersOptions
to define per page size.当我们使用
listBlobContainers
方法列出容器时,如果它的数量大于 5000,它将分页。我们也可以使用ListBlobContainersOptions
来定义每页大小。 For more details, please refer to here and here有关更多详细信息,请参阅此处和此处
for example例如
String endpoint = String.format(Locale.ROOT, "https://%s.blob.core.windows.net", accountName);
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint(endpoint)
.credential(credential)
.buildClient();
ListBlobContainersOptions options = new ListBlobContainersOptions();
options.setMaxResultsPerPage(5);
PagedIterable<BlobContainerItem> pagedIterableResponse= blobServiceClient.listBlobContainers(options, null);
Iterator<PagedResponse<BlobContainerItem>> ite = pagedIterableResponse.iterableByPage().iterator();
int i =1;
while(ite.hasNext()){
PagedResponse<BlobContainerItem> items= ite.next();
System.out.println("The containers in the page "+i);
i++;
for (BlobContainerItem item: items.getValue()
) {
System.out.println("\t"+item.getName());
}
}
We can use the following method to get the continuation token我们可以使用下面的方法来获取延续令牌
List<BlobItem> allBlobs = new ArrayList<>();
String continuationToken;
ListBlobsOptions options = new ListBlobsOptions().setMaxResultsPerPage(5);
Iterator<PagedResponse<BlobItem>> response = containerClient.listBlobs(options, Duration.ofSeconds(30)).iterableByPage().iterator();
do {
PagedResponse<BlobItem> pagedResponse = response.next();
List<BlobItem> blobs = pagedResponse.getValue();
continuationToken = pagedResponse.getContinuationToken();
blobs.forEach(b -> System.out.println(b.getName()));
allBlobs.addAll(blobs);
} while (continuationToken != null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.