Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, 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
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.s3.transfer.internal;
 
 import java.io.File;
 
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 java.io.FileInputStream.
 
 
     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()
                 .withBucketName()
                 .withKey()
                 .withUploadId()
                 .withInputStream(new InputSubstream(, 0, partSizeisLastPart))
                 .withPartNumber(++)
                 .withPartSize(partSize);
         } else {
             req = new UploadPartRequest()
                 .withBucketName()
                 .withKey()
                 .withUploadId()
                 .withFile()
                 .withFileOffset()
                 .withPartNumber(++)
                 .withPartSize(partSize);
         }
         TransferManager.appendMultipartUserAgent(req);
        if ( != nullreq.setSSECustomerKey();
         += partSize;
         -= partSize;
        req.setLastPart(isLastPart);
           ;
        return req;
    }
    public int getTotalNumberOfParts() {
        return ;
    }
New to GrepCode? Check out our FAQ X