本文整理匯總了Java中com.amazonaws.services.s3.transfer.Upload.waitForCompletion方法的典型用法代碼示例。如果您正苦於以下問題:Java Upload.waitForCompletion方法的具體用法?Java Upload.waitForCompletion怎麽用?Java Upload.waitForCompletion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.s3.transfer.Upload
的用法示例。
在下文中一共展示了Upload.waitForCompletion方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: uploadToS3
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
private String uploadToS3(String bucket, String key, MultipartFile file) {
final AmazonS3 s3 = s3ClientFactory.createClient();
final TransferManager transferManager = TransferManagerBuilder.standard().withS3Client(s3).build();
try {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(file.getSize());
metadata.setContentType(file.getContentType());
byte[] resultByte = DigestUtils.md5(file.getBytes());
String streamMD5 = new String(Base64.encodeBase64(resultByte));
metadata.setContentMD5(streamMD5);
Upload upload = transferManager.upload(bucket, key, file.getInputStream(), metadata);
upload.waitForCompletion();
return streamMD5;
} catch (AmazonServiceException | InterruptedException | IOException e) {
logger.error("Error uploading file: {}", e.toString());
return null;
} finally {
transferManager.shutdownNow();
}
}
示例2: updateSnapshotIndex
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
/**
* Write a list of all of the state versions to S3.
* @param newVersion
*/
private synchronized void updateSnapshotIndex(Long newVersion) {
/// insert the new version into the list
int idx = Collections.binarySearch(snapshotIndex, newVersion);
int insertionPoint = Math.abs(idx) - 1;
snapshotIndex.add(insertionPoint, newVersion);
/// build a binary representation of the list -- gap encoded variable-length integers
byte[] idxBytes = buidGapEncodedVarIntSnapshotIndex();
/// indicate the Content-Length
ObjectMetadata metadata = new ObjectMetadata();
metadata.setHeader("Content-Length", (long)idxBytes.length);
/// upload the new file content.
try(InputStream is = new ByteArrayInputStream(idxBytes)) {
Upload upload = s3TransferManager.upload(bucketName, getSnapshotIndexObjectName(blobNamespace), is, metadata);
upload.waitForCompletion();
} catch(Exception e) {
throw new RuntimeException(e);
}
}
示例3: putChunk
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
public long putChunk(String localDataFile, String localIndexFile, TopicPartition tp) throws IOException {
// Put data file then index, then finally update/create the last_index_file marker
String dataFileKey = this.getChunkFileKey(localDataFile);
String idxFileKey = this.getChunkFileKey(localIndexFile);
// Read offset first since we'll delete the file after upload
long nextOffset = getNextOffsetFromIndexFileContents(new FileReader(localIndexFile));
try {
Upload upload = tm.upload(this.bucket, dataFileKey, new File(localDataFile));
upload.waitForCompletion();
upload = tm.upload(this.bucket, idxFileKey, new File(localIndexFile));
upload.waitForCompletion();
} catch (Exception e) {
throw new IOException("Failed to upload to S3", e);
}
this.updateCursorFile(idxFileKey, tp);
// Sanity check - return what the new nextOffset will be based on the index we just uploaded
return nextOffset;
}
示例4: Upload
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
public void Upload(String key, InputStream input, long size) throws InterruptedException {
ObjectMetadata meta = new ObjectMetadata();
if(SSE)
meta.setServerSideEncryption(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
meta.setContentLength(size);
Upload upload = tm.upload(existingBucketName, key, input, meta);
try {
// Or you can block and wait for the upload to finish
upload.waitForCompletion();
Logger.DEBUG("Upload complete.");
} catch (AmazonClientException amazonClientException) {
Logger.DEBUG("Unable to upload file, upload was aborted.");
Logger.EXCEPTION(amazonClientException);
}
}
示例5: uploadArtifactStream
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
private void uploadArtifactStream(IndexArtifact ia, StorageRequest sr) throws LocalStorageException
{
try
{
TransferManager tx = new TransferManager(client);
ObjectMetadata om = new ObjectMetadata();
om.setContentLength(sr.getLength());
String key = getPath() + ia.getLocation() + "/" + sr.getFilename();
Upload myUpload = tx.upload(bucketName, key, sr.getNewStream(), om);
myUpload.waitForCompletion();
}
catch (Exception exc)
{
logger.error(exc.getLocalizedMessage());
throw new LocalStorageException(exc);
}
}
示例6: store
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
@Override
public void store( final Movie movie ) throws MovieNotStoredException
{
final String key = movie.getMovieId().getMovieId();
logger.info( "Uploading {} to S3 key {}", movie, key );
final File movieFile = movie.getPath().toFile();
final PutObjectRequest putObjectRequest = new PutObjectRequest( S3_BUCKET_HOOD_ETS_SOURCE, key, movieFile );
final ProgressListener progressListener = new S3ProgressListener( key, movieFile.length() );
try
{
final Upload upload = this.transferManager.upload( putObjectRequest );
upload.addProgressListener( progressListener );
upload.waitForCompletion();
}
catch ( AmazonClientException | InterruptedException e )
{
this.transferManager.abortMultipartUploads( S3_BUCKET_HOOD_ETS_SOURCE, new Date() );
throw new MovieNotStoredException( movie, e );
}
logger.info( "Upload complete." );
}
示例7: call
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
@Override
public Integer call() throws Exception {
TransferManager t = new TransferManager(amazonS3Client);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setUserMetadata(metadata);
if(sse) {
objectMetadata.setSSEAlgorithm(SSEAlgorithm.AES256.getAlgorithm());
}
Upload u = t.upload(new PutObjectRequest(bucket, key, inputFile).withMetadata(objectMetadata));
// TODO this listener spews out garbage >100% on a retry, add a test to verify
if (progressListener != null) {
progressListener.withTransferProgress(new TransferProgressWrapper(u.getProgress()));
u.addProgressListener(progressListener);
}
try {
u.waitForCompletion();
} finally {
t.shutdownNow();
}
return 0;
}
示例8: uploadFile
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
private void uploadFile(File file, String s3ObjectName, ObjectMetadata metadata) {
try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
Upload upload = s3TransferManager.upload(bucketName, s3ObjectName, is, metadata);
upload.waitForCompletion();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例9: store
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
@Override
public void store(File file) throws Exception {
LogUtils.debug(LOG_TAG, "Uploading new file. Name: " + file.getName());
TransferManager tm = new TransferManager(new DefaultAWSCredentialsProviderChain());
// TransferManager processes all transfers asynchronously,
// so this call will return immediately.
Upload upload = tm.upload(bucketName, file.getName(), file);
upload.waitForCompletion();
LogUtils.debug(LOG_TAG, "Successfully uploaded file to bucket.\nName: " + file.getName() + "\nBucket name: " +
bucketName);
tm.shutdownNow();
}
示例10: transferFileToS3
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
private void transferFileToS3(final String key) {
final long fileSizeMb = file.length() / (1024 * 1024);
getLogger().info("Uploading {} MB from file {} to {}", fileSizeMb, file, getS3Url());
final TransferManager transferManager = createTransferManager();
final Instant start = Instant.now();
final Upload upload = transferManager.upload(config.getDeploymentBucket(), key, file);
try {
upload.waitForCompletion();
getLogger().info("Uploaded {} to {} in {}", file, getS3Url(), Duration.between(start, Instant.now()));
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new AssertionError("Upload interrupted", e);
}
}
示例11: run
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
@Override
public void run(final PublishLambdaCommand command) {
final URL artifactUrl = command.getArtifactUrl();
final BaseOutputs outputParameters = configStore.getBaseStackOutputs();
final String configBucketName = outputParameters.getConfigBucketName();
if (StringUtils.isBlank(configBucketName)) {
final String errorMessage = "The specified environment isn't configured properly!";
logger.error(errorMessage);
throw new IllegalStateException(errorMessage);
}
initClient(configBucketName);
final File filePath = downloadArtifact(artifactUrl);
try {
final Upload upload =
transferManager.upload(configBucketName, command.getLambdaName().getBucketKey(), filePath);
logger.info("Uploading lambda artifact.");
upload.waitForCompletion();
logger.info("Uploading complete.");
} catch (InterruptedException e) {
logger.error("Interrupted while waiting for upload to complete!", e);
} finally {
transferManager.shutdownNow(false);
}
}
示例12: uploadToS3
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
public void uploadToS3(String s3bucket, String targetDirectory, File sourceDirectory) {
// Recursively upload sourceDirectory to targetDirectory.
FOR: for (final File file : sourceDirectory.listFiles()) {
if (file.isDirectory()) {
uploadToS3(s3bucket, targetDirectory + "/" + file.getName(), file);
} else if (file.isFile()) {
final String path = file.getAbsolutePath();
final long uploadStartTimeMs = System.currentTimeMillis();
final PutObjectRequest putRequest = new PutObjectRequest(s3bucket, targetDirectory + "/" + file.getName(), file)
.withCannedAcl(CannedAccessControlList.PublicRead);
final Upload upload = transferManager.upload(putRequest);
int statusChecks = 0;
System.out.println("Uploading " + path);
while (!upload.isDone()) {
if (uploadTimedOut(uploadStartTimeMs)) {
System.err.format("Timed out uploading file to S3 (%s). Will skip file. Report might be incomplete.%n", path);
continue FOR;
}
sleep(100);
if (++statusChecks % 100 == 0) {
System.out.format("Still uploading %s%n", file.getAbsolutePath());
}
}
try {
upload.waitForCompletion();
} catch (Exception e) {
System.out.format("Failed to upload to S3 %s/%s/%s%n", s3bucket, targetDirectory, file.getName());
e.printStackTrace();
}
}
}
}
示例13: uploadFile
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
public void uploadFile(File file, ObjectMetadata metadata, String bucketName, String fileUploadPath) throws AmazonClientException {
LOGGER.info("Uploading file " + file.getAbsolutePath() + " to Amazon S3 bucket " + bucketName);
try {
metadata.setContentLength(file.length());
Upload upload = tm.upload(bucketName, fileUploadPath, new FileInputStream(file), metadata);
upload.waitForCompletion();
} catch (Exception e) {
LOGGER.info("File upload for " + file.getAbsolutePath() + " to Amazon S3 bucket " + bucketName + " failed");
throw new AmazonClientException(e.getMessage(), e);
}
LOGGER.info("File upload for " + file.getAbsolutePath() + " to Amazon S3 bucket " + bucketName + " completed successfully");
}
示例14: uploadFileToS3
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
/**
* Uploads a file to S3 and returns the s3 file key. The bucket that is used is configured the properties file via
* s3.bucket
*
* @param s3Bucket the s3 bucket name
* @param localFile the local file to be uploaded
* @param s3FileKey the s3 file key that should be used
* @return a 2-element array, where element 0 is the s3 bucket and element 1 is the s3 file key
*/
public String[] uploadFileToS3(String s3Bucket, final Path localFile, final String s3FileKey)
throws IOException, InterruptedException {
if (localFile == null) {
throw new NullPointerException("localFile was null.");
}
if (isEmpty(s3FileKey)) {
throw new NullPointerException("objectFileKey cannot be null");
}
if (logger.isTraceEnabled()) {
logger.trace(format("uploadFileToS3(%s)", localFile.getFileName().toString()));
}
AWSCredentials awsCredentials = AmazonAWSHelper.getCredentials();
TransferManager tx = new TransferManager(awsCredentials);
ObjectMetadata metadata = new ObjectMetadata();
final String contentType = detectContentTypeFromFilename(s3FileKey);
if (logger.isDebugEnabled()) {
logger.debug(format("Setting contentType to '%s' in metadata for S3 object '%s'", contentType, s3FileKey));
}
metadata.setContentType(contentType);
Upload myUpload = tx.upload(s3Bucket, s3FileKey, Files.newInputStream(localFile), metadata);
myUpload.waitForCompletion();
String[] retval = {s3Bucket, s3FileKey};
if (logger.isDebugEnabled()) {
logger.debug(format("Upload to S3 was successful. bucket: '%s', file key: '%s'", s3Bucket, s3FileKey));
}
return retval;
}
示例15: uploadTextToS3Bucket
import com.amazonaws.services.s3.transfer.Upload; //導入方法依賴的package包/類
public void uploadTextToS3Bucket(String bucketName, String key, String content, String storageClass) throws TranscodeException{
ObjectMetadata objectMetaData = new ObjectMetadata();
byte[] bytes = content.getBytes();
objectMetaData.setContentLength(bytes.length);
objectMetaData.setContentType("text/html; charset=utf-8");
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, inputStream, objectMetaData);
if (storageClass.equalsIgnoreCase(StorageClass.ReducedRedundancy.name())) {
putObjectRequest.setStorageClass(StorageClass.ReducedRedundancy);
}
final long fileSizeInBytes = bytes.length;
putObjectRequest.setGeneralProgressListener(new ProgressListener() {
private long bytesTransferred = 0;
private int currentPercentage = 0;
@Override
public void progressChanged(ProgressEvent progressEvent) {
bytesTransferred += progressEvent.getBytesTransferred();
int percentTransferred = (int) (bytesTransferred * 100 / fileSizeInBytes);
if (percentTransferred%10 == 0 && percentTransferred != currentPercentage) {
logger.info("Transferred {}% of {} bytes.", percentTransferred, fileSizeInBytes);
currentPercentage = percentTransferred;
}
}
});
Upload upload = tm.upload(putObjectRequest);
if (upload!=null) {
upload.waitForCompletion();
} else {
logger.error("Did not get upload detail from S3 for asset with key " + key);
throw new TranscodeException("Did not get upload detail from S3 for asset with key " + key);
}
} catch (AmazonClientException | InterruptedException e) {
throw new TranscodeException(e.getMessage());
}
}