Example usage for com.amazonaws.event ProgressListenerChain ProgressListenerChain

List of usage examples for com.amazonaws.event ProgressListenerChain ProgressListenerChain

Introduction

In this page you can find the example usage for com.amazonaws.event ProgressListenerChain ProgressListenerChain.

Prototype

public ProgressListenerChain(ProgressListener... listeners) 

Source Link

Document

Create a listener chain that directly passes all the progress events to the specified listeners.

Usage

From source file:br.com.ingenieux.mojo.aws.util.BeanstalkerS3Client.java

License:Apache License

@Override
public PutObjectResult putObject(PutObjectRequest req) throws AmazonClientException, AmazonServiceException {
    if (!multipartUpload) {
        return super.putObject(req);
    }//from www .j a  v a 2 s. c o m

    final long contentLen = TransferManagerUtils.getContentLength(req);

    String tempFilename = req.getKey() + ".tmp";
    String origFilename = req.getKey();

    req.setKey(tempFilename);

    XProgressListener progressListener = new XProgressListener();

    req.setGeneralProgressListener(new ProgressListenerChain(progressListener));

    progressListener.setContentLen(contentLen);
    progressListener.setUpload(transferManager.upload(req));
    progressListener.setSilentUpload(silentUpload);

    try {
        progressListener.getUpload().waitForCompletion();
    } catch (InterruptedException e) {
        throw new AmazonClientException(e.getMessage(), e);
    }

    CopyObjectRequest copyReq = new CopyObjectRequest(req.getBucketName(), tempFilename, req.getBucketName(),
            origFilename);

    copyObject(copyReq);

    deleteObject(new DeleteObjectRequest(req.getBucketName(), tempFilename));

    return null;
}