Search in sources :

Example 1 with TransferState

use of com.amazonaws.services.s3.transfer.Transfer.TransferState in project aws-doc-sdk-examples by awsdocs.

the class XferMgrProgress method uploadFileWithListener.

public static void uploadFileWithListener(String file_path, String bucket_name, String key_prefix, boolean pause) {
    System.out.println("file: " + file_path + (pause ? " (pause)" : ""));
    String key_name = null;
    if (key_prefix != null) {
        key_name = key_prefix + '/' + file_path;
    } else {
        key_name = file_path;
    }
    File f = new File(file_path);
    TransferManager xfer_mgr = new TransferManager();
    try {
        Upload u = xfer_mgr.upload(bucket_name, key_name, f);
        // print an empty progress bar...
        printProgressBar(0.0);
        u.addProgressListener(new ProgressListener() {

            public void progressChanged(ProgressEvent e) {
                double pct = e.getBytesTransferred() * 100.0 / e.getBytes();
                eraseProgressBar();
                printProgressBar(pct);
            }
        });
        // block with Transfer.waitForCompletion()
        XferMgrProgress.waitForCompletion(u);
        // print the final state of the transfer.
        TransferState xfer_state = u.getState();
        System.out.println(": " + xfer_state);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    xfer_mgr.shutdownNow();
}
Also used : TransferManager(com.amazonaws.services.s3.transfer.TransferManager) ProgressListener(com.amazonaws.event.ProgressListener) AmazonServiceException(com.amazonaws.AmazonServiceException) Upload(com.amazonaws.services.s3.transfer.Upload) MultipleFileUpload(com.amazonaws.services.s3.transfer.MultipleFileUpload) ProgressEvent(com.amazonaws.event.ProgressEvent) File(java.io.File) TransferState(com.amazonaws.services.s3.transfer.Transfer.TransferState)

Example 2 with TransferState

use of com.amazonaws.services.s3.transfer.Transfer.TransferState in project aws-doc-sdk-examples by awsdocs.

the class XferMgrProgress method showMultiUploadProgress.

// Prints progress of a multiple file upload while waiting for it to finish.
public static void showMultiUploadProgress(MultipleFileUpload multi_upload) {
    // print the upload's human-readable description
    System.out.println(multi_upload.getDescription());
    Collection<? extends Upload> sub_xfers = new ArrayList<Upload>();
    sub_xfers = multi_upload.getSubTransfers();
    do {
        System.out.println("\nSubtransfer progress:\n");
        for (Upload u : sub_xfers) {
            System.out.println("  " + u.getDescription());
            if (u.isDone()) {
                TransferState xfer_state = u.getState();
                System.out.println("  " + xfer_state);
            } else {
                TransferProgress progress = u.getProgress();
                double pct = progress.getPercentTransferred();
                printProgressBar(pct);
                System.out.println();
            }
        }
        // wait a bit before the next update.
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            return;
        }
    } while (multi_upload.isDone() == false);
    // print the final state of the transfer.
    TransferState xfer_state = multi_upload.getState();
    System.out.println("\nMultipleFileUpload " + xfer_state);
}
Also used : ArrayList(java.util.ArrayList) Upload(com.amazonaws.services.s3.transfer.Upload) MultipleFileUpload(com.amazonaws.services.s3.transfer.MultipleFileUpload) TransferState(com.amazonaws.services.s3.transfer.Transfer.TransferState) TransferProgress(com.amazonaws.services.s3.transfer.TransferProgress)

Example 3 with TransferState

use of com.amazonaws.services.s3.transfer.Transfer.TransferState in project aws-doc-sdk-examples by awsdocs.

the class XferMgrProgress method showTransferProgress.

// Prints progress while waiting for the transfer to finish.
public static void showTransferProgress(Transfer xfer) {
    // print the transfer's human-readable description
    System.out.println(xfer.getDescription());
    // print an empty progress bar...
    printProgressBar(0.0);
    // update the progress bar while the xfer is ongoing.
    do {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            return;
        }
        // Note: so_far and total aren't used, they're just for
        // documentation purposes.
        TransferProgress progress = xfer.getProgress();
        long so_far = progress.getBytesTransferred();
        long total = progress.getTotalBytesToTransfer();
        double pct = progress.getPercentTransferred();
        eraseProgressBar();
        printProgressBar(pct);
    } while (xfer.isDone() == false);
    // print the final state of the transfer.
    TransferState xfer_state = xfer.getState();
    System.out.println(": " + xfer_state);
}
Also used : TransferState(com.amazonaws.services.s3.transfer.Transfer.TransferState) TransferProgress(com.amazonaws.services.s3.transfer.TransferProgress)

Aggregations

TransferState (com.amazonaws.services.s3.transfer.Transfer.TransferState)3 MultipleFileUpload (com.amazonaws.services.s3.transfer.MultipleFileUpload)2 TransferProgress (com.amazonaws.services.s3.transfer.TransferProgress)2 Upload (com.amazonaws.services.s3.transfer.Upload)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ProgressEvent (com.amazonaws.event.ProgressEvent)1 ProgressListener (com.amazonaws.event.ProgressListener)1 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1