List<ChunkInfo> getChunksToStitch(CompleteMultipartUpload completeMultipartUpload) throws RestServiceException {
      // Get parts in order from CompleteMultipartUpload, deserialize each part id to get data chunk ids.
      List<Part> parts = validatePartsOrThrow(completeMultipartUpload);
      List<ChunkInfo> chunkInfos = new ArrayList<>();
      try {
        // sort the list in order
        Collections.sort(parts, Comparator.comparingInt(Part::getPartNumber));
        String reservedMetadataId = null;
        for (Part part : parts) {
          S3MultipartETag eTag = S3MultipartETag.deserialize(part.geteTag());
          // TODO [S3]: decide the life cycle of S3.
          long expirationTimeInMs = -1;

          if (eTag.getVersion() == S3MultipartETag.VERSION_1) {
            List<Pair<String, Long>> chunks = eTag.getOrderedChunkIdSizeList();
            for (int i = 0; i < chunks.size(); i++) {
              String blobId = chunks.get(i).getFirst();
              long chunkSize = chunks.get(i).getSecond();

              ChunkInfo chunk = new ChunkInfo(blobId, chunkSize, expirationTimeInMs, reservedMetadataId);
              chunkInfos.add(chunk);
            }
          } else {
            String error = "Wrong ETag version " + completeMultipartUpload + " rest request " + restRequest;
            LOGGER.error(error);
            throw new RestServiceException(error, RestServiceErrorCode.BadRequest);
          }
        }
      } catch (IOException e) {
        String error = "Could not parse xml request body " + completeMultipartUpload + " rest request " + restRequest;
        LOGGER.error(error);
        throw new RestServiceException(error, e, RestServiceErrorCode.BadRequest);
      }
      return chunkInfos;
    }
Parse and verify the part IDs in the body of a CompleteMultipartUpload request.
@param completeMultipartUpload {@link CompleteMultipartUpload} request
@return a list of chunks to stitch that can be provided to the router.
ambry-frontend/src/main/java/com/github/ambry/frontend/s3/S3MultipartCompleteUploadHandler.java