private static void deleteEvents(CalendarService service,
List<CalendarEventEntry> eventsToDelete) throws ServiceException,
IOException {
// Add each item in eventsToDelete to the batch request.
CalendarEventFeed batchRequest = new CalendarEventFeed();
for (int i = 0; i < eventsToDelete.size(); i++) {
CalendarEventEntry toDelete = eventsToDelete.get(i);
// Modify the entry toDelete with batch ID and operation type.
BatchUtils.setBatchId(toDelete, String.valueOf(i));
BatchUtils.setBatchOperationType(toDelete, BatchOperationType.DELETE);
batchRequest.getEntries().add(toDelete);
}
// Get the URL to make batch requests to
CalendarEventFeed feed = service.getFeed(eventFeedUrl,
CalendarEventFeed.class);
Link batchLink = feed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM);
URL batchUrl = new URL(batchLink.getHref());
// Submit the batch request
CalendarEventFeed batchResponse = service.batch(batchUrl, batchRequest);
// Ensure that all the operations were successful.
boolean isSuccess = true;
for (CalendarEventEntry entry : batchResponse.getEntries()) {
String batchId = BatchUtils.getBatchId(entry);
if (!BatchUtils.isSuccess(entry)) {
isSuccess = false;
BatchStatus status = BatchUtils.getBatchStatus(entry);
System.out.println("\n" + batchId + " failed (" + status.getReason()