Search in sources :

Example 1 with MultipleFileUpload

use of com.amazonaws.services.s3.transfer.MultipleFileUpload 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 2 with MultipleFileUpload

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

the class XferMgrProgress method uploadDirWithSubprogress.

public static void uploadDirWithSubprogress(String dir_path, String bucket_name, String key_prefix, boolean recursive, boolean pause) {
    System.out.println("directory: " + dir_path + (recursive ? " (recursive)" : "") + (pause ? " (pause)" : ""));
    TransferManager xfer_mgr = new TransferManager();
    try {
        MultipleFileUpload multi_upload = xfer_mgr.uploadDirectory(bucket_name, key_prefix, new File(dir_path), recursive);
        // loop with Transfer.isDone()
        XferMgrProgress.showMultiUploadProgress(multi_upload);
        // or block with Transfer.waitForCompletion()
        XferMgrProgress.waitForCompletion(multi_upload);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    xfer_mgr.shutdownNow();
}
Also used : TransferManager(com.amazonaws.services.s3.transfer.TransferManager) AmazonServiceException(com.amazonaws.AmazonServiceException) File(java.io.File) MultipleFileUpload(com.amazonaws.services.s3.transfer.MultipleFileUpload)

Example 3 with MultipleFileUpload

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

the class XferMgrUpload method uploadDir.

public static void uploadDir(String dir_path, String bucket_name, String key_prefix, boolean recursive, boolean pause) {
    System.out.println("directory: " + dir_path + (recursive ? " (recursive)" : "") + (pause ? " (pause)" : ""));
    TransferManager xfer_mgr = new TransferManager();
    try {
        MultipleFileUpload xfer = xfer_mgr.uploadDirectory(bucket_name, key_prefix, new File(dir_path), recursive);
        // loop with Transfer.isDone()
        XferMgrProgress.showTransferProgress(xfer);
        // or block with Transfer.waitForCompletion()
        XferMgrProgress.waitForCompletion(xfer);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    xfer_mgr.shutdownNow();
}
Also used : TransferManager(com.amazonaws.services.s3.transfer.TransferManager) AmazonServiceException(com.amazonaws.AmazonServiceException) File(java.io.File) MultipleFileUpload(com.amazonaws.services.s3.transfer.MultipleFileUpload)

Example 4 with MultipleFileUpload

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

the class XferMgrUpload method uploadFileList.

public static void uploadFileList(String[] file_paths, String bucket_name, String key_prefix, boolean pause) {
    System.out.println("file list: " + Arrays.toString(file_paths) + (pause ? " (pause)" : ""));
    // convert the file paths to a list of File objects (required by the
    // uploadFileList method)
    ArrayList<File> files = new ArrayList<File>();
    for (String path : file_paths) {
        files.add(new File(path));
    }
    TransferManager xfer_mgr = new TransferManager();
    try {
        MultipleFileUpload xfer = xfer_mgr.uploadFileList(bucket_name, key_prefix, new File("."), files);
        // loop with Transfer.isDone()
        XferMgrProgress.showTransferProgress(xfer);
        // or block with Transfer.waitForCompletion()
        XferMgrProgress.waitForCompletion(xfer);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    xfer_mgr.shutdownNow();
}
Also used : TransferManager(com.amazonaws.services.s3.transfer.TransferManager) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) File(java.io.File) MultipleFileUpload(com.amazonaws.services.s3.transfer.MultipleFileUpload)

Aggregations

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