This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 71aee7f CAMEL-12126: camel-ftp - Add option for resume download. 71aee7f is described below commit 71aee7f854e3decd4e4811fffb515cb875740dec Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Jan 9 13:43:17 2018 +0100 CAMEL-12126: camel-ftp - Add option for resume download. --- .../remote/DefaultFtpClientActivityListener.java | 25 ++++++++++++++++------ .../src/main/resources/ftp.properties | 4 +++- .../src/main/resources/log4j2.properties | 7 ++++++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultFtpClientActivityListener.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultFtpClientActivityListener.java index 5ebabfb..8e424a4 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultFtpClientActivityListener.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultFtpClientActivityListener.java @@ -34,6 +34,8 @@ public class DefaultFtpClientActivityListener implements FtpClientActivityListen private final String host; private final FtpEndpoint endpoint; private boolean download = true; + private boolean resume; + private long resumeOffset; private String fileName; private long fileSize; @@ -140,6 +142,8 @@ public class DefaultFtpClientActivityListener implements FtpClientActivityListen @Override public void onBeginDownloading(String host, String file) { download = true; + resume = false; + resumeOffset = 0; watch.restart(); interval.restart(); String msg = "Downloading from host: " + host + " file: " + file + " starting "; // add extra space to align with completed @@ -152,20 +156,26 @@ public class DefaultFtpClientActivityListener implements FtpClientActivityListen @Override public void onResumeDownloading(String host, String file, long position) { download = true; + resume = true; + resumeOffset = position; watch.restart(); interval.restart(); - String msg = "Resume downloading from host: " + host + " file: " + file + " at position: " + position + " (" + StringHelper.humanReadableBytes(position) + ")"; + String msg = "Resume downloading from host: " + host + " file: " + file + " at position: " + position + " bytes/" + StringHelper.humanReadableBytes(position); if (fileSize > 0) { - msg += " (size: " + fileSizeText + ")"; + float percent = ((float) resumeOffset / (float) fileSize) * 100L; + String num = String.format("%.1f", percent); + msg += "/" + num + "% (size: " + fileSizeText + ")"; } doLog(msg); } @Override public void onDownload(String host, String file, long chunkSize, long totalChunkSize, long fileSize) { + totalChunkSize = totalChunkSize + resumeOffset; transferredBytes = totalChunkSize; - String msg = "Downloading from host: " + host + " file: " + file + " chunk (" + chunkSize + "/" + totalChunkSize + " bytes)"; + String prefix = resume ? "Resume downloading" : "Downloading"; + String msg = prefix + " from host: " + host + " file: " + file + " chunk (" + chunkSize + "/" + totalChunkSize + " bytes)"; if (fileSize > 0) { float percent = ((float) totalChunkSize / (float) fileSize) * 100L; String num = String.format("%.1f", percent); @@ -173,7 +183,8 @@ public class DefaultFtpClientActivityListener implements FtpClientActivityListen if (totalChunkSize < fileSize && "100.0".equals(num)) { num = "99.9"; } - msg += " (progress: " + num + "%)"; + String size = StringHelper.humanReadableBytes(totalChunkSize); + msg += " (progress: " + size + "/" + num + "%)"; } else { // okay we do not know the total size, but then make what we have download so-far human readable String size = StringHelper.humanReadableBytes(totalChunkSize); @@ -189,7 +200,8 @@ public class DefaultFtpClientActivityListener implements FtpClientActivityListen @Override public void onDownloadComplete(String host, String file) { - String msg = "Downloading from host: " + host + " file: " + file + " completed"; + String prefix = resume ? "Resume downloading" : "Downloading"; + String msg = prefix + " from host: " + host + " file: " + file + " completed"; if (transferredBytes > 0) { msg += " (size: " + StringHelper.humanReadableBytes(transferredBytes) + ")"; } @@ -223,7 +235,8 @@ public class DefaultFtpClientActivityListener implements FtpClientActivityListen if (totalChunkSize < fileSize && "100.0".equals(num)) { num = "99.9"; } - msg += " (progress: " + num + "%)"; + String size = StringHelper.humanReadableBytes(totalChunkSize); + msg += " (progress: " + size + "/" + num + "%)"; } else { // okay we do not know the total size, but then make what we have uploaded so-far human readable String size = StringHelper.humanReadableBytes(totalChunkSize); diff --git a/examples/camel-example-ftp/src/main/resources/ftp.properties b/examples/camel-example-ftp/src/main/resources/ftp.properties index 5159c81..f3b9a07 100644 --- a/examples/camel-example-ftp/src/main/resources/ftp.properties +++ b/examples/camel-example-ftp/src/main/resources/ftp.properties @@ -19,7 +19,9 @@ ##ftp.client=ftp://changeme-to-ftp-server.com:21/mypath?autoCreate=false&username=bob&password=123 # this example is a local FTP server -ftp.client=ftp://localhost:21?autoCreate=false&username=bob&password=123&passiveMode=true&binary=true&resumeDownload=true&localWorkDirectory=target/ftp-work&transferLoggingLevel=INFO&transferLoggingIntervalSeconds=1 +ftp.client=ftp://localhost:21?autoCreate=false&username=bob&password=123&passiveMode=true&binary=true\ + &resumeDownload=true&localWorkDirectory=target/ftp-work\ + &transferLoggingLevel=INFO&transferLoggingIntervalSeconds=1&transferLoggingVerbose=false # for the server we want to delay 5 seconds between polling the server # and keep the downloaded file as-is diff --git a/examples/camel-example-ftp/src/main/resources/log4j2.properties b/examples/camel-example-ftp/src/main/resources/log4j2.properties index d406a9f..4a910bf 100644 --- a/examples/camel-example-ftp/src/main/resources/log4j2.properties +++ b/examples/camel-example-ftp/src/main/resources/log4j2.properties @@ -15,9 +15,16 @@ ## limitations under the License. ## --------------------------------------------------------------------------- +appender.file.type = File +appender.file.name = file +appender.file.fileName = target/camel-example-ftp.log +appender.file.layout.type = PatternLayout +appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n + appender.out.type = Console appender.out.name = out appender.out.layout.type = PatternLayout appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n rootLogger.level = INFO +rootLogger.appenderRef.file.ref = file rootLogger.appenderRef.out.ref = out -- To stop receiving notification emails like this one, please contact ['"commits@camel.apache.org" <commits@camel.apache.org>'].