In Microsoft graph sdk 6.4.0 using new PageIterator - what is the proper way to use processPageItemCallback?

20 views Asked by At

There is a new PageIterator in 6.4.0 version of Microsoft Graph Java SDK.

https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/docs/upgrade-to-v6.md#pageiterator

Let's say you have a page iterator and you want to read some bytes from several list items.

PageIterator<ListItem, ListItemCollectionResponse> pageIterator = new PageIterator.Builder<ListItem, ListItemCollectionResponse>()
    .client(graphClient)
    // The first page of the collection is passed to the collectionPage method
    .collectionPage(response)
    // CollectionPageFactory is called to create a new collection page from the nextLink
    .collectionPageFactory(ListItemCollectionResponse::createFromDiscriminatorValue)
    // ProcessPageItemCallback is called for each item in the collection
    .processPageItemCallback(li -> {
        String driveItemId = li.getDriveItem().getId();
        InputStream is = graphClient.drives().byDriveId(siteDriveId)
                .items()
                .byDriveItemId(driveItemId)
                .content()
                .get();
        try {
            byte[] bytes = IOUtils.toByteArray(is);
            LOGGER.info("Read {} bytes", bytes.length);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return true; // why does this return true? What if i returned false?
    }).build();
pageIterator.iterate();

Am I appropriately using the processPageItemCallback by doing work inside there? Or should I be storing it in a List and using the list afterwards. Why does it return true/false?

0

There are 0 answers