當前位置: 首頁>>代碼示例>>Java>>正文


Java Upload.waitForCompletion方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:grassrootza,項目名稱:grassroot-platform,代碼行數:23,代碼來源:StorageBrokerImpl.java

示例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);
    }
}
 
開發者ID:Netflix,項目名稱:hollow-reference-implementation,代碼行數:27,代碼來源:S3Publisher.java

示例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;
}
 
開發者ID:DeviantArt,項目名稱:kafka-connect-s3,代碼行數:22,代碼來源:S3Writer.java

示例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);
    }
}
 
開發者ID:biointec,項目名稱:halvade,代碼行數:17,代碼來源:AWSUploader.java

示例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);
    }
}
 
開發者ID:Spedge,項目名稱:hangar,代碼行數:20,代碼來源:S3Storage.java

示例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." );
}
 
開發者ID:stevenmhood,項目名稱:transcoder,代碼行數:22,代碼來源:S3MovieRepository.java

示例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;
}
 
開發者ID:rholder,項目名稱:esthree,代碼行數:25,代碼來源:Put.java

示例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);
       }
}
 
開發者ID:Netflix,項目名稱:hollow-reference-implementation,代碼行數:10,代碼來源:S3Publisher.java

示例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();
}
 
開發者ID:darshanmaiya,項目名稱:MCSFS,代碼行數:14,代碼來源:S3Store.java

示例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);
	}
}
 
開發者ID:kaklakariada,項目名稱:aws-sam-gradle,代碼行數:15,代碼來源:S3UploadTask.java

示例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);
    }
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-lifecycle-cli,代碼行數:29,代碼來源:PublishLambdaOperation.java

示例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();
            }
        }
    }
}
 
開發者ID:electronicarts,項目名稱:gatling-aws-maven-plugin,代碼行數:37,代碼來源:AwsGatlingRunner.java

示例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");
}
 
開發者ID:ktenzer,項目名稱:snap2cloud,代碼行數:15,代碼來源:S3Util.java

示例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;
}
 
開發者ID:srinikandula,項目名稱:mybus,代碼行數:40,代碼來源:AWSClient.java

示例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());			
	}
}
 
開發者ID:TimShi,項目名稱:s3_video,代碼行數:43,代碼來源:AWSAdapter.java


注:本文中的com.amazonaws.services.s3.transfer.Upload.waitForCompletion方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。