Example usage for com.amazonaws.event ProgressEventType isByteCountEvent

List of usage examples for com.amazonaws.event ProgressEventType isByteCountEvent

Introduction

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

Prototype

public boolean isByteCountEvent() 

Source Link

Document

Returns true if this even type is associated with some number of bytes; false otherwise.

Usage

From source file:com.github.rholder.esthree.progress.PrintingProgressListener.java

License:Apache License

@Override
public void progressChanged(ProgressEvent progressEvent) {
    ProgressEventType type = progressEvent.getEventType();
    if (type.equals(TRANSFER_COMPLETED_EVENT) || type.equals(TRANSFER_STARTED_EVENT)) {
        out.println();/* w w w .  j ava  2  s .  co  m*/
    }

    if (type.isByteCountEvent()) {
        long timeLeft = getTimeLeft();
        if (lastTimeLeft < 1 && timeLeft > 0) {
            // prime this value with a sane starting point
            lastTimeLeft = timeLeft;
        }

        // use an exponential moving average to smooth the estimate
        lastTimeLeft += 0.90 * (timeLeft - lastTimeLeft);

        out.print(String.format("\r%1$s  %2$s / %3$s  %4$s      ",
                generate(saturatedCast(round(completed + (progress.getPercentTransferred() * multiplier)))),
                humanReadableByteCount(progress.getBytesTransferred(), true),
                humanReadableByteCount(progress.getTotalBytesToTransfer(), true), fromSeconds(lastTimeLeft)));
        out.flush();
    }
}