private MicrosoftApiResponse uploadStreamInChunks(
      long totalFileSize, String itemUploadUrl, String itemMimeType, InputStream inputStream)
      throws IOException, DestinationMemoryFullException, PermissionDeniedException {
    MicrosoftApiResponse lastChunkResponse = null;
    StreamChunker streamChunker = new StreamChunker(MICROSOFT_UPLOAD_CHUNK_BYTE_SIZE, inputStream);
    Optional<DataChunk> currentChunk;
    while (true) {
      currentChunk = streamChunker.nextChunk();
      if (currentChunk.isEmpty()) {
        break;
      }
      lastChunkResponse =
          uploadChunk(currentChunk.get(), itemUploadUrl, totalFileSize, itemMimeType);

      // Log our progress before continuing to the next chunk.
      final DataChunk lastChunksent = currentChunk.get();
      final int httpStatus = lastChunkResponse.httpStatus();
      monitor.info(
          () ->
              String.format(
                  "Uploaded chunk range %d-%d (of total bytesize: %d) successfuly, HTTP status %d",
                  lastChunksent.streamByteOffset(),
                  lastChunksent.finalByteOffset(),
                  totalFileSize,
                  httpStatus));
    }
    return checkNotNull(
        lastChunkResponse, "bug: empty-stream already checked for yet stream empty now?");
  }
Depletes input stream, uploading a chunk of the stream at a time, throwing a DTP exception
along the way if any unrecoverable errors are encountered.
extensions/data-transfer/portability-data-transfer-microsoft/src/main/java/org/datatransferproject/transfer/microsoft/media/MicrosoftMediaImporter.java