NET-604 TFTP send & receive don't have progress indication

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/net/trunk@1782077 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c782ca5..87cd593 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -87,6 +87,9 @@
   The POP3Mail examples can now get password from console, stdin or an environment variable.
   
 ">
+            <action issue="NET-604" type="fix" dev="sebb" due-to="Frank Delporte">
+            TFTP send & receive don't have progress indication
+            </action>
             <action issue="NET-588" type="fix" dev="sebb" due-to="Dave Nice / Thai H">
             FTPClient.setPassiveNatWorkaround assumes host is outside site local range
             </action>
diff --git a/src/main/java/org/apache/commons/net/tftp/TFTPClient.java b/src/main/java/org/apache/commons/net/tftp/TFTPClient.java
index ef4f1b7..79e31fc 100644
--- a/src/main/java/org/apache/commons/net/tftp/TFTPClient.java
+++ b/src/main/java/org/apache/commons/net/tftp/TFTPClient.java
@@ -65,6 +65,12 @@
     /*** The maximum number of timeouts allowed before failing. ***/
     private int __maxTimeouts;
 
+    /*** The number of bytes received in the ongoing download. ***/
+    private long totalBytesReceived = 0;
+
+    /*** The number of bytes sent in the ongoing upload. ***/
+    private long totalBytesSent = 0;
+
     /***
      * Creates a TFTPClient instance with a default timeout of DEFAULT_TIMEOUT,
      * maximum timeouts value of DEFAULT_MAX_TIMEOUTS, a null socket,
@@ -106,6 +112,20 @@
     }
 
 
+    /**
+     * @return The number of bytes received in the ongoing download
+     */
+    public long getTotalBytesReceived() {
+        return totalBytesReceived;
+    }
+
+    /**
+     * @return The number of bytes sent in the ongoing download
+     */
+    public long getTotalBytesSent() {
+        return totalBytesSent;
+    }
+
     /***
      * Requests a named file from a remote host, writes the
      * file to an OutputStream, closes the connection, and returns the number
@@ -135,6 +155,7 @@
         beginBufferedOps();
 
         dataLength = lastBlock = hostPort = bytesRead = 0;
+        totalBytesReceived = 0;
         block = 1;
 
         if (mode == TFTP.ASCII_MODE) {
@@ -277,6 +298,7 @@
             ack.setBlockNumber(lastBlock);
             sent = ack;
             bytesRead += dataLength;
+            totalBytesReceived += dataLength;
         } // First data packet less than 512 bytes signals end of stream.
 
         while (dataLength == TFTPPacket.SEGMENT_SIZE);
@@ -386,6 +408,7 @@
         beginBufferedOps();
 
         dataLength = lastBlock = hostPort = bytesRead = totalThisPacket = 0;
+        totalBytesSent = 0L;
         block = 0;
         boolean lastAckWait = false;
 
@@ -541,6 +564,7 @@
             data.setBlockNumber(block);
             data.setData(_sendBuffer, 4, totalThisPacket);
             sent = data;
+            totalBytesSent += totalThisPacket;
         }
         while ( totalThisPacket > 0 || lastAckWait );
         // Note: this was looping while dataLength == 0 || lastAckWait,