本文整理汇总了Java中com.amazonaws.services.s3.model.UploadPartRequest类的典型用法代码示例。如果您正苦于以下问题:Java UploadPartRequest类的具体用法?Java UploadPartRequest怎么用?Java UploadPartRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UploadPartRequest类属于com.amazonaws.services.s3.model包,在下文中一共展示了UploadPartRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startWorker
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
protected void startWorker(UploadPartRequest req, int retries) {
int id = req.getPartNumber();
CompletableFuture<Void> f = CompletableFuture
.supplyAsync(() -> s3.uploadPart(req), executor)
.handle((res, error) -> {
workers.remove(id);
if (res != null) {
done.add(res);
}
if (error != null && isOpen()) {
if (retries < failedPartUploadRetries) {
startWorker(req, retries + 1);
} else {
this.error = new IllegalStateException("Could not upload part " + id + " after "
+ retries + " retries. Aborting upload", error.getCause());
cancel();
}
}
return null;
});
workers.put(id, f);
}
示例2: testFailedUploadPart
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
@Test
void testFailedUploadPart() throws Exception {
final AmazonS3 mocked = mock(AmazonS3.class);
s3channel = (S3AppendableObjectChannel) defaultBuilder("id")
.failedPartUploadRetries(3)
.amazonS3(mocked)
.build();
when(mocked.uploadPart(any())).thenThrow(new TestException());
s3channel.skip(MIN_PART_SIZE).write(ByteBuffer.allocate(123));
while (s3channel.getCancellation() == null) {
Thread.sleep(25);
}
s3channel.getCancellation().get();
assertTrue(!s3channel.getCancellation().isCompletedExceptionally());
assertFalse(s3channel.isOpen());
//coverage
s3channel.startWorker(new UploadPartRequest().withPartNumber(1), 0);
assertThrows(IllegalStateException.class, () -> s3channel.write(ByteBuffer.allocate(1)));
verify(mocked, times(1)).abortMultipartUpload(any());
}
示例3: uploadPartAsync
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
public void uploadPartAsync(ByteArrayInputStream inputStream,
int partSize) {
final int currentPartNumber = partETagsFutures.size() + 1;
final UploadPartRequest request =
new UploadPartRequest().withBucketName(bucket).withKey(key)
.withUploadId(uploadId).withInputStream(inputStream)
.withPartNumber(currentPartNumber).withPartSize(partSize);
request.setGeneralProgressListener(progressListener);
ListenableFuture<PartETag> partETagFuture =
executorService.submit(new Callable<PartETag>() {
@Override
public PartETag call() throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("Uploading part {} for id '{}'", currentPartNumber,
uploadId);
}
return client.uploadPart(request).getPartETag();
}
});
partETagsFutures.add(partETagFuture);
}
示例4: uploadPartsInParallel
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
/**
* Submits a callable for each part to upload to our thread pool and records its corresponding Future.
*/
private void uploadPartsInParallel(UploadPartRequestFactory requestFactory,
String uploadId) {
Map<Integer,PartSummary> partNumbers = identifyExistingPartsForResume(uploadId);
while (requestFactory.hasMoreRequests()) {
if (threadPool.isShutdown()) throw new CancellationException("TransferManager has been shutdown");
UploadPartRequest request = requestFactory.getNextUploadPartRequest();
if (partNumbers.containsKey(request.getPartNumber())) {
PartSummary summary = partNumbers.get(request.getPartNumber());
eTagsToSkip.add(new PartETag(request.getPartNumber(), summary
.getETag()));
transferProgress.updateProgress(summary.getSize());
continue;
}
futures.add(threadPool.submit(new UploadPartCallable(s3, request)));
}
}
示例5: computeLastPartSize
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
@Override
final long computeLastPartSize(UploadPartRequest request) {
long plaintextLength;
if (request.getFile() != null) {
if (request.getPartSize() > 0)
plaintextLength = request.getPartSize();
else
plaintextLength = request.getFile().length();
} else if (request.getInputStream() != null) {
plaintextLength = request.getPartSize();
} else {
return -1;
}
long cipherBlockSize = contentCryptoScheme.getBlockSizeInBytes();
long offset = cipherBlockSize - (plaintextLength % cipherBlockSize);
return plaintextLength + offset;
}
示例6: call
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
@Override
public UploadPartResult call() throws Exception {
try {
return this.amazonS3.uploadPart(new UploadPartRequest().withBucketName(this.bucketName).
withKey(this.key).
withUploadId(this.uploadId).
withInputStream(new ByteArrayInputStream(this.content)).
withPartNumber(this.partNumber).
withLastPart(this.last).
withPartSize(this.contentLength));
} finally {
//Release the memory, as the callable may still live inside the CompletionService which would cause
// an exhaustive memory usage
this.content = null;
}
}
示例7: doUploadMultipart
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
protected PartETag doUploadMultipart(S3BlobStore blobStore, String bucketName, String blobName, String uploadId, InputStream is,
int length, boolean lastPart) throws AmazonS3Exception {
UploadPartRequest request = new UploadPartRequest()
.withBucketName(bucketName)
.withKey(blobName)
.withUploadId(uploadId)
.withPartNumber(multipartChunks)
.withInputStream(is)
.withPartSize(length)
.withLastPart(lastPart);
UploadPartResult response = blobStore.client().uploadPart(request);
return response.getPartETag();
}
示例8: uploadPart
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
@Override
public UploadPartResult uploadPart(UploadPartRequest uploadPartRequest) throws AmazonClientException, AmazonServiceException {
throw new UnsupportedOperationException();
}
示例9: createRequest
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
protected UploadPartRequest createRequest(int id, ByteBuffer buffer) {
buffer.rewind();
return new UploadPartRequest()
.withBucketName(bucket)
.withKey(key)
.withUploadId(uploadId)
.withPartNumber(id)
.withPartSize(buffer.limit())
.withInputStream(new ByteArrayInputStream(buffer.array(), 0, buffer.limit()));
}
示例10: getNextUploadPartRequest
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
public synchronized UploadPartRequest getNextUploadPartRequest() {
long partSize = Math.min(optimalPartSize, remainingBytes);
boolean isLastPart = (remainingBytes - partSize <= 0);
UploadPartRequest req = null;
if (wrappedStream != null) {
req = new UploadPartRequest()
.withBucketName(bucketName)
.withKey(key)
.withUploadId(uploadId)
.withInputStream(new InputSubstream(wrappedStream, 0, partSize, isLastPart))
.withPartNumber(partNumber++)
.withPartSize(partSize);
} else {
req = new UploadPartRequest()
.withBucketName(bucketName)
.withKey(key)
.withUploadId(uploadId)
.withFile(file)
.withFileOffset(offset)
.withPartNumber(partNumber++)
.withPartSize(partSize);
}
req.withRequesterPays(origReq.isRequesterPays());
TransferManager.appendMultipartUserAgent(req);
if (sseCustomerKey != null) req.setSSECustomerKey(sseCustomerKey);
offset += partSize;
remainingBytes -= partSize;
req.setLastPart(isLastPart);
req.withGeneralProgressListener(origReq.getGeneralProgressListener())
.withRequestMetricCollector(origReq.getRequestMetricCollector())
;
req.getRequestClientOptions().setReadLimit(origReq.getReadLimit());
return req;
}
示例11: uploadPartsInSeries
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
/**
* Uploads all parts in the request in serial in this thread, then completes
* the upload and returns the result.
*/
private UploadResult uploadPartsInSeries(UploadPartRequestFactory requestFactory) {
final List<PartETag> partETags = new ArrayList<PartETag>();
while (requestFactory.hasMoreRequests()) {
if (threadPool.isShutdown()) throw new CancellationException("TransferManager has been shutdown");
UploadPartRequest uploadPartRequest = requestFactory.getNextUploadPartRequest();
// Mark the stream in case we need to reset it
InputStream inputStream = uploadPartRequest.getInputStream();
if (inputStream != null && inputStream.markSupported()) {
if (uploadPartRequest.getPartSize() >= Integer.MAX_VALUE) {
inputStream.mark(Integer.MAX_VALUE);
} else {
inputStream.mark((int)uploadPartRequest.getPartSize());
}
}
partETags.add(s3.uploadPart(uploadPartRequest).getPartETag());
}
CompleteMultipartUploadRequest req =
new CompleteMultipartUploadRequest(
origReq.getBucketName(), origReq.getKey(), multipartUploadId,
partETags)
.withRequesterPays(origReq.isRequesterPays())
.withGeneralProgressListener(origReq.getGeneralProgressListener())
.withRequestMetricCollector(origReq.getRequestMetricCollector())
;
CompleteMultipartUploadResult res = s3.completeMultipartUpload(req);
UploadResult uploadResult = new UploadResult();
uploadResult.setBucketName(res.getBucketName());
uploadResult.setKey(res.getKey());
uploadResult.setETag(res.getETag());
uploadResult.setVersionId(res.getVersionId());
return uploadResult;
}
示例12: useChunkEncoding
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
/**
* Determine whether to use aws-chunked for signing
*/
private boolean useChunkEncoding(SignableRequest<?> request) {
// If chunked encoding is explicitly disabled through client options return right here.
// Chunked encoding only makes sense to do when the payload is signed
if (!isPayloadSigningEnabled(request) || isChunkedEncodingDisabled(request)) {
return false;
}
if (request.getOriginalRequestObject() instanceof PutObjectRequest
|| request.getOriginalRequestObject() instanceof UploadPartRequest) {
return true;
}
return false;
}
示例13: newMultipartS3CipherInputStream
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
protected final CipherLiteInputStream newMultipartS3CipherInputStream(
UploadPartRequest req, CipherLite cipherLite) {
final File fileOrig = req.getFile();
final InputStream isOrig = req.getInputStream();
InputStream isCurr = null;
try {
if (fileOrig == null) {
if (isOrig == null) {
throw new IllegalArgumentException(
"A File or InputStream must be specified when uploading part");
}
isCurr = isOrig;
} else {
isCurr = new ResettableInputStream(fileOrig);
}
isCurr = new InputSubstream(isCurr,
req.getFileOffset(),
req.getPartSize(),
req.isLastPart());
return cipherLite.markSupported()
? new CipherLiteInputStream(isCurr, cipherLite,
DEFAULT_BUFFER_SIZE,
IS_MULTI_PART, req.isLastPart())
: new RenewableCipherLiteInputStream(isCurr, cipherLite,
DEFAULT_BUFFER_SIZE,
IS_MULTI_PART, req.isLastPart());
} catch (Exception e) {
cleanupDataSource(req, fileOrig, isOrig, isCurr, log);
throw failure(e,"Unable to create cipher input stream");
}
}
示例14: onPartCreate
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
/**
* Notified from {@link MultiFileOutputStream#fos()} when a part ready for
* upload has been successfully created on disk. By default, this method
* performs the following:
* <ol>
* <li>calls {@link #newUploadPartRequest(PartCreationEvent, File)} to
* create an upload-part request for the newly created ciphertext file</li>
* <li>call {@link #appendUserAgent(AmazonWebServiceRequest, String)} to
* append the necessary user agent string to the request</li>
* <li>and finally submit a concurrent task, which calls the method
* {@link #uploadPart(UploadPartRequest)}, to be performed</li>
* </ol>
* <p>
* To enable parallel uploads, implementation of this method should never
* block.
*
* @param event
* to represent the completion of a ciphertext file creation
* which is ready for multipart upload to S3.
*/
public void onPartCreate(PartCreationEvent event) {
final File part = event.getPart();
final UploadPartRequest reqUploadPart =
newUploadPartRequest(event, part);
final OnFileDelete fileDeleteObserver = event.getFileDeleteObserver();
appendUserAgent(reqUploadPart, AmazonS3EncryptionClient.USER_AGENT);
futures.add(es.submit(new Callable<UploadPartResult>() {
@Override public UploadPartResult call() {
// Upload the ciphertext directly via the non-encrypting
// s3 client
try {
return uploadPart(reqUploadPart);
} finally {
// clean up part already uploaded
if (!part.delete()) {
LogFactory.getLog(getClass()).debug(
"Ignoring failure to delete file " + part
+ " which has already been uploaded");
} else {
if (fileDeleteObserver != null)
fileDeleteObserver.onFileDelete(null);
}
}
}
}));
}
示例15: newUploadPartRequest
import com.amazonaws.services.s3.model.UploadPartRequest; //导入依赖的package包/类
/**
* Creates and returns an upload-part request corresponding to a ciphertext
* file upon a part-creation event.
*
* @param event
* the part-creation event of the ciphertxt file.
* @param part
* the created ciphertext file corresponding to the upload-part
*/
protected UploadPartRequest newUploadPartRequest(PartCreationEvent event,
final File part) {
final UploadPartRequest reqUploadPart = new UploadPartRequest()
.withBucketName(req.getBucketName())
.withFile(part)
.withKey(req.getKey())
.withPartNumber(event.getPartNumber())
.withPartSize(part.length())
.withLastPart(event.isLastPart())
.withUploadId(uploadId)
.withObjectMetadata(req.getUploadPartMetadata())
;
return reqUploadPart;
}