Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2010-2015, Inc. or its affiliates. All Rights Reserved.
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
  * or in the "license" file accompanying this file. This file is distributed
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
Factory for creating all the individual UploadPartRequest objects for a multipart upload.

This allows us to delay creating each UploadPartRequest until we're ready for it, instead of immediately creating thousands of UploadPartRequest objects for each large upload, when we won't need most of those request objects for a while.

 public class UploadPartRequestFactory {
     private final String bucketName;
     private final String key;
     private final String uploadId;
     private final long optimalPartSize;
     private final File file;
     private final PutObjectRequest origReq;
     private int partNumber = 1;
     private long offset = 0;
     private long remainingBytes;
     private SSECustomerKey sseCustomerKey;
     private final int totalNumberOfParts;

Wrapped to provide necessary mark-and-reset support for the underlying input stream. In particular, it provides support for unlimited mark-and-reset if the underlying stream is a
     public UploadPartRequestFactory(PutObjectRequest origReqString uploadIdlong optimalPartSize) {
         this. = origReq;
         this. = uploadId;
         this. = optimalPartSize;
         this. = origReq.getBucketName();
         this. = origReq.getKey();
         this. = TransferManagerUtils.getRequestFile(origReq);
         this. = TransferManagerUtils.getContentLength(origReq);
         this. = origReq.getSSECustomerKey();
         this. = (int) Math.ceil((doublethis.
                 / this.);
         if (origReq.getInputStream() != null) {
              = ReleasableInputStream.wrap(origReq.getInputStream());
     public synchronized boolean hasMoreRequests() {
         return ( > 0);
     public synchronized UploadPartRequest getNextUploadPartRequest() {
         long partSize = Math.min();
         boolean isLastPart = ( - partSize <= 0);
         UploadPartRequest req = null;
         if ( != null) {
             req = new UploadPartRequest()
                 .withInputStream(new InputSubstream(, 0, partSizeisLastPart))
         } else {
             req = new UploadPartRequest()
        if ( != nullreq.setSSECustomerKey();
         += partSize;
         -= partSize;
        return req;
    public int getTotalNumberOfParts() {
        return ;
New to GrepCode? Check out our FAQ X