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
Date Mon, 05 Apr 2004 14:13:59 GMT
I noticed that the attachment somehow disappeared from my posting so here it
is inline:

Index: ScpToMessage.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpT
oMessage.java,v
retrieving revision 1.8
diff -B -b -u -r1.8 ScpToMessage.java
--- ScpToMessage.java 9 Feb 2004 21:05:34 -0000 1.8
+++ ScpToMessage.java 5 Apr 2004 13:57:01 -0000
@@ -150,8 +150,9 @@
         byte[] buf = new byte[BUFFER_SIZE];
         long startTime = System.currentTimeMillis();
         int totalLength = 0;
+        int percentTransMitted = 0;
         try {
-            log("Sending: " + localFile.getName() + " : " +
localFile.length());
+            log("Sending: " + localFile.getName() + " : " +
localFile.length() + " bytes");
             while (true) {
                 int len = fis.read(buf, 0, buf.length);
                 if (len <= 0) {
@@ -159,6 +160,9 @@
                 }
                 out.write(buf, 0, len);
                 totalLength += len;
+                // only track prgress for files larger than 100kb
+                if (filesize > 102400)
+                    percentTransMitted = trackProgress(filesize,
totalLength, percentTransMitted);
             }
             out.flush();
             sendAck(out);
@@ -170,6 +174,25 @@
         }
     }
+    /*
+        Track progress every 10% if 100kb < filesize < 1mb. For larger
files trck progress for every percent transmitted.
+    */
+    private 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 && (percent % 10 != 0) ) {
+                // do not track between tenths
+            }
+            else {
+                log("" + percent + "%");
+            }
+        }
+
+        return percent;
+    }
+
     public File getLocalFile() {
         return localFile;
     }


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


Mime
View raw message