Example usage for com.amazonaws.event ProgressEvent getBytes

List of usage examples for com.amazonaws.event ProgressEvent getBytes

Introduction

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

Prototype

public long getBytes() 

Source Link

Document

Returns the number of bytes associated with the event.

Usage

From source file:aws.example.s3.XferMgrProgress.java

License:Open Source License

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;//from w w  w  .  j a  va2 s  .com
    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();
}