diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java index 087e9f6ec7..97d4553433 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/internal/BaseBlobStore.java @@ -354,14 +354,24 @@ public abstract class BaseBlobStore implements BlobStore { MultipartUpload mpu = initiateMultipartUpload(container, blob.getMetadata(), overrides); try { long contentLength = blob.getMetadata().getContentMetadata().getContentLength(); + // TODO: inject MultipartUploadSlicingAlgorithm to override default part size MultipartUploadSlicingAlgorithm algorithm = new MultipartUploadSlicingAlgorithm( getMinimumMultipartPartSize(), getMaximumMultipartPartSize(), getMaximumNumberOfParts()); long partSize = algorithm.calculateChunkSize(contentLength); int partNumber = 1; - for (Payload payload : slicer.slice(blob.getPayload(), partSize)) { + // TODO: for InputStream payloads, this buffers all parts in-memory! + while (partNumber < algorithm.getParts()) { + Payload payload = slicer.slice(blob.getPayload(), algorithm.getCopied(), partSize); BlobUploader b = new BlobUploader(mpu, partNumber++, payload); parts.add(executor.submit(b)); + algorithm.addCopied(partSize); + } + if (algorithm.getRemaining() != 0) { + Payload payload = slicer.slice(blob.getPayload(), algorithm.getCopied(), algorithm.getRemaining()); + BlobUploader b = + new BlobUploader(mpu, partNumber, payload); + parts.add(executor.submit(b)); } return completeMultipartUpload(mpu, Futures.getUnchecked(Futures.allAsList(parts))); } catch (RuntimeException re) { diff --git a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/MultipartUploadSlicingAlgorithm.java b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/MultipartUploadSlicingAlgorithm.java index 455ab623f8..eb4074f972 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/MultipartUploadSlicingAlgorithm.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/MultipartUploadSlicingAlgorithm.java @@ -132,8 +132,7 @@ public final class MultipartUploadSlicingAlgorithm { this.copied = copied; } - @VisibleForTesting - protected int getParts() { + public int getParts() { return parts; } @@ -141,7 +140,7 @@ public final class MultipartUploadSlicingAlgorithm { return ++part; } - protected void addCopied(long copied) { + public void addCopied(long copied) { this.copied += copied; } @@ -156,8 +155,7 @@ public final class MultipartUploadSlicingAlgorithm { return chunkSize; } - @VisibleForTesting - protected long getRemaining() { + public long getRemaining() { return remaining; }