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 CopyPartRequest objects for a multipart copy.

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

public class CopyPartRequestFactory {

Upload id to be used in each copy part request.
    private final String uploadId;
Optimal size of each part in the copy request.
    private final long optimalPartSize;
The original copy object request.
    private final CopyObjectRequest origReq;
Part Number to be specified in each copy part request.
    private int partNumber = 1;
Starting byte for each part.
    private long offset = 0;
The number of remaining bytes to be copied.
    private long remainingBytes;
            String uploadIdlong optimalPartSizelong contentLength) {
        this. = origReq;
        this. = uploadId;
        this. = optimalPartSize;
        this. = contentLength;
    public synchronized boolean hasMoreRequests() {
        return ( > 0);

Constructs a copy part requests and returns it.

Returns a new copy part request
    public synchronized CopyPartRequest getNextCopyPartRequest() {
        final long partSize = Math.min();
        CopyPartRequest req = new CopyPartRequest()
            .withLastByte(Long.valueOf( + partSize - 1))
            // other meta data
            // general meta data
         += partSize;
         -= partSize;
        return req;
New to GrepCode? Check out our FAQ X