From c42b8fd3d5d9a6f7a90dd5a42354bc0819f9810a Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Tue, 22 Aug 2017 17:21:48 +0200 Subject: [PATCH] Fixed issue with to large ftp upload size --- .idea/modules/app/app.iml | 1 + .../core/behaviour/UeBehaviourFtpUpload.java | 28 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.idea/modules/app/app.iml b/.idea/modules/app/app.iml index 3a0f669..f5481e4 100755 --- a/.idea/modules/app/app.iml +++ b/.idea/modules/app/app.iml @@ -78,6 +78,7 @@ + diff --git a/app/src/main/java/com/ericsson/uecontrol/core/behaviour/UeBehaviourFtpUpload.java b/app/src/main/java/com/ericsson/uecontrol/core/behaviour/UeBehaviourFtpUpload.java index b5e9f0b..a3fb401 100755 --- a/app/src/main/java/com/ericsson/uecontrol/core/behaviour/UeBehaviourFtpUpload.java +++ b/app/src/main/java/com/ericsson/uecontrol/core/behaviour/UeBehaviourFtpUpload.java @@ -16,7 +16,7 @@ import java.util.regex.Pattern; */ public class UeBehaviourFtpUpload extends UeBehaviourFtp { private static final Logger log = Logger.getLogger(UeBehaviourFtpUpload.class); - private static final int BUFFER_SIZE = 512; + private static final int BUFFER_SIZE = 8192; @Configurable(order=1, value="Host") @@ -38,8 +38,8 @@ public class UeBehaviourFtpUpload extends UeBehaviourFtp { if (outStream != null) { OutputStream out = new BufferedOutputStream(outStream); - if(sizeOrFile != null && Pattern.matches("\\d*", sizeOrFile)){ - int size = Integer.parseInt(sizeOrFile); + if(isLong(sizeOrFile)){ + long size = Long.parseLong(sizeOrFile); uploadRandomData(out, size); } else{ @@ -55,13 +55,13 @@ public class UeBehaviourFtpUpload extends UeBehaviourFtp { } } - private void uploadRandomData(OutputStream out, int size) throws IOException { + private void uploadRandomData(OutputStream out, long size) throws IOException { // Upload data log.debug("Uploading random data with size "+size); - int total = 0; + long total = 0; byte[] data = new byte[BUFFER_SIZE]; while (total < size && !stopExecution()) { - int writeLength = (total + data.length < size ? data.length : size - total); + int writeLength = (int)(total + data.length < size ? data.length : size - total); out.write(data, 0, writeLength); total += writeLength; @@ -109,11 +109,19 @@ public class UeBehaviourFtpUpload extends UeBehaviourFtp { @Override public String toString() { - if(sizeOrFile != null && Pattern.matches("\\d*", sizeOrFile)){ - int size = Integer.parseInt(sizeOrFile); - return "Will upload "+ StringUtil.getByteString(size) +" of random data."; + if (sizeOrFile != null) { + if (isLong(sizeOrFile)) { + long size = Long.parseLong(sizeOrFile); + return "Will upload " + StringUtil.getByteString(size) + " of random data."; + } + else + return "Will upload local file " + sizeOrFile; } - return "Will upload local file "+ sizeOrFile; + else + return "No file specified"; } + private boolean isLong(String str){ + return sizeOrFile != null && Pattern.matches("\\d{1,19}", str); + } }