ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rami Ojares" <rami.oja...@elisa.fi>
Subject Re: SSH tracking - Take 4
Date Wed, 07 Apr 2004 14:29:49 GMT
> Thanks, I've committed the patch with some (minor) modifications.

The pleasure is mine.

> What we need now, are docs.

Yep, I think also Jsch would need some docs and an API that does not need
one to write
bytes by hand but that is another story. I can help of course with the docs
(but slowly :)

> Also, I'm not sure whether the form of the progess report is really
> optimal, that's why I haven't merged it over to the 1.6 branch yet.
> <get> will print lines of dots each line taking up to 50 columns.
> Each dot represents approximately 1K.  We could do one dot per percent
> or something like that.  Right now, you'd get 100 lines in your
> logfile for larger transfers which looks a little too noisy.

Here is the reading loop of <get>

byte[] buffer = new byte[100 * 1024];
int length;
int dots = 0;

while ((length = is.read(buffer)) >= 0) {
    fos.write(buffer, 0, length);
    if (verbose) {
        System.out.print(".");
        if (dots++ > 50) {
            System.out.flush();
            dots = 0;
        }
    }
}

So it prints one dot for every 100KB.
And the way they end up on the same line is that only 50*100KB is read
it flushes. Meaning that user does not see the dots coming one by one but
in chunk of 50 ( = 50 * 100KB)

I am not sure if this interpretation is correct but so I understand this.
The problem is that the user sees the progress not often enough.
And of course when the dots are bound to KB instead of percentage
with large files they start taking space. Some might like that.

Anyway here is a smarter version of method trackProgress()
This will output 2 lines for any size file and give visual cue about
progress quite well. Try it!

Kippis!

/*
    Track progress every 10% if 100kb < filesize < 1mb. For larger files
track progress for every percent transmitted.
*/
protected int trackProgress(int filesize, int totalLength, int
percentTransmitted) {

    int percent = (int) Math.round(Math.floor((totalLength /
(double)filesize) * 100));

    if (percent > percentTransmitted) {
        if ( filesize < 1048576 ) {
            if (percent % 10 == 0) {
                if (percent == 100)
                    System.out.println(" 100%");
                else
                    System.out.print("*");
            }
            else
                return percent;
        }
        else {
            if (percent == 50)
                System.out.println(" 50%");
            else if (percent == 100)
                System.out.println(" 100%");
            else
                System.out.print(".");
        }
    }

    System.out.flush();
    return percent;
}


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message