Example usage for org.apache.maven.repository ArtifactTransferEvent getTransferredBytes

List of usage examples for org.apache.maven.repository ArtifactTransferEvent getTransferredBytes

Introduction

In this page you can find the example usage for org.apache.maven.repository ArtifactTransferEvent getTransferredBytes.

Prototype

public long getTransferredBytes() 

Source Link

Usage

From source file:org.commonjava.emb.boot.log.BatchTransferListener.java

License:Apache License

protected void doCompleted(final ArtifactTransferEvent transferEvent) {
    final ArtifactTransferResource artifact = transferEvent.getResource();
    final long contentLength = transferEvent.getTransferredBytes();
    if (contentLength >= 0) {
        final String type = (transferEvent.getRequestType() == ArtifactTransferEvent.REQUEST_PUT ? "Uploaded"
                : "Downloaded");
        final String len = contentLength >= 1024 ? toKB(contentLength) + " KB" : contentLength + " B";

        String throughput = "";
        final long duration = System.currentTimeMillis() - artifact.getTransferStartTime();
        if (duration > 0) {
            final DecimalFormat format = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ENGLISH));
            final double kbPerSec = (contentLength / 1024.0) / (duration / 1000.0);
            throughput = " at " + format.format(kbPerSec) + " KB/sec";
        }/*from ww  w  . j  a va 2 s. c  o  m*/

        out.println(type + ": " + artifact.getUrl() + " (" + len + throughput + ")");
    }
}

From source file:org.commonjava.emb.boot.log.InteractiveTransferListener.java

License:Apache License

protected void doProgress(final ArtifactTransferEvent transferEvent) {
    final ArtifactTransferResource resource = transferEvent.getResource();
    downloads.put(resource, Long.valueOf(transferEvent.getTransferredBytes()));

    final StringBuilder buffer = new StringBuilder(64);

    for (final Map.Entry<ArtifactTransferResource, Long> entry : downloads.entrySet()) {
        final long total = entry.getKey().getContentLength();
        final long complete = entry.getValue().longValue();

        buffer.append(getStatus(complete, total)).append("  ");
    }//from  ww w.  j a  v  a  2  s.co  m

    final int pad = lastLength - buffer.length();
    lastLength = buffer.length();
    pad(buffer, pad);
    buffer.append('\r');

    out.print(buffer);
}

From source file:org.sonatype.gshell.artifact.monitor.ProgressSpinnerMonitor.java

License:Apache License

public void transferProgress(final ArtifactTransferEvent event) {
    assert event != null;

    long total = event.getResource().getContentLength();
    complete += event.getTransferredBytes();

    String message = renderProgressBytes(complete, total);

    print(spinner.spin(message));/*from  w w w.j  av a 2s .  c o m*/
}

From source file:org.sonatype.gshell.artifact.monitor.ProgressSpinnerMonitor.java

License:Apache License

public void transferCompleted(final ArtifactTransferEvent event) {
    assert event != null;

    spinner.stop();/*from w w w .  java 2 s  .  c  o  m*/

    long total = event.getTransferredBytes();
    String type = renderRequestTypeFinished(event);
    String bytes = renderBytes(total);

    print(Ansi.ansi().eraseLine().toString());
    print(type + " " + bytes);

}