commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tapan Karecha" <tap...@india.hp.com>
Subject [patch] NetComponents - FTPClient's restart functionality
Date Fri, 20 Sep 2002 10:45:23 GMT
This is a patch to fix the restart functionality in FTPClient. Following is
the summary of changes:

- Added a setter method "public void setRestartOffset(long)". This method
should be called every time (if restart is required) before a file retrieve
method is called. After the file is retrieved, the restart offset is set to
0. If this method is not called, the retrieve begins at the start of file.

- Added getter method "public long getRestartOffset()" that returns the
value of restart offset.

- Changed signature of restart(long) so that it is now private. This is
internally called from __openDataConnection(int command, String arg) if the
method setRestartOffset(long) was called with a positive long value.

A couple of lines in the diff may wrap onto the next line. If this is a
problem in applying this patch, how should I upload the patch file to
someplace from where it can be picked up by you?

Also, can you suggest how can this be unit tested so that I can write a test
and send it?

- Tapan.

==== diff patch ====

--- FTPClient.java.orig	Fri Sep 20 14:44:53 2002
+++ FTPClient.java	Fri Sep 20 14:44:51 2002
@@ -246,6 +246,7 @@
     private int __fileType, __fileFormat, __fileStructure,
__fileTransferMode;
     private boolean __remoteVerificationEnabled;
     private FTPFileListParser __fileListParser;
+    private long __restartOffset;

     /***
      * Default FTPClient constructor.  Creates a new FTPClient instance
@@ -357,6 +358,12 @@
                 server.close();
                 return null;
             }
+
+            if ((__restartOffset > 0) && !restart(__restartOffset))
+            {
+                server.close();
+                return null;
+            }

             if (!FTPReply.isPositivePreliminary(sendCommand(command, arg)))
             {
@@ -1548,11 +1555,38 @@
      * @exception IOException  If an I/O error occurs while either sending
a
      *      command to the server or receiving a reply from the server.
      ***/
-    public boolean restart(long offset) throws IOException
+    private boolean restart(long offset) throws IOException
     {
+        __restartOffset = 0;
         return
FTPReply.isPositiveIntermediate(rest(Long.toString(offset)));
     }

+    /***
+     * Sets the restart offset. The restart command is sent to the server
+     * only before sending the file transfer command. When this is done,
+     * the restart marker is reset
+     * <p>
+     * @param offset  The offset into the remote file at which to start the
+     *           next file transfer.
+     ***/
+    public void setRestartOffset(long offset)
+    {
+        if (offset > 0)
+            __restartOffset = offset;
+    }
+
+    /***
+     * Fetches the restart offset.
+     * <p>
+     * @return offset  The offset into the remote file at which to start
the
+     *           next file transfer.
+     ***/
+    public long getRestartOffset()
+    {
+        return __restartOffset;
+    }
+
+

     /***
      * Renames a remote file.


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message