summaryrefslogtreecommitdiffstats
path: root/vnfmarket-be
diff options
context:
space:
mode:
authorMurali Mohan Murthy Potham <murali.p@huawei.com>2017-09-21 12:25:22 +0000
committerGerrit Code Review <gerrit@onap.org>2017-09-21 12:25:22 +0000
commitf62c962e71909ed14b1c5c80a6f36717f649d97f (patch)
tree742d3e8d8c64cd09cda720fbeb456f1264976c1b /vnfmarket-be
parent1d2cfe589baddb0f1586f6eb1e2fdbb0cd43e562 (diff)
parent8926c547cb3c9b07df87c6f31fda5d43b5ae76a4 (diff)
Merge "split function into smaller ones"
Diffstat (limited to 'vnfmarket-be')
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java88
1 files changed, 58 insertions, 30 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java
index 1d5d46f9..432ee219 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java
@@ -32,6 +32,36 @@ public class ToolUtil {
private ToolUtil() {
}
+
+ /**
+ * copy in directory.
+ * @param srcDirName source directory name
+ * @param destDirName destination directory name
+ * @param files file list in directory
+ * @param overlay overwrite or not
+ * @return boolean
+ * @throws IOException e
+ */
+ public static boolean copyInDirectory(String srcDirName, String destDirName, File[] files, boolean overlay)
+ throws IOException
+ {
+ for (int i = 0; i < files.length; i++) {
+ boolean flag = false;
+ if (files[i].isFile()) {
+ flag = copyFile(files[i].getAbsolutePath(), destDirName + files[i].getName(), true);
+ }
+ if (files[i].isDirectory()) {
+ flag = copyDirectory(files[i].getAbsolutePath(), destDirName + files[i].getName(), overlay);
+ }
+ if (!flag) {
+ String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!";
+ LOGGER.error(message);
+ return false;
+ }
+ }
+ return true;
+ }
+
/**
* copy from directory.
* @param srcDirName source directory name
@@ -57,22 +87,36 @@ public class ToolUtil {
} else if ((destDir.exists() && !overlay) || (!destDir.exists() && !destDir.mkdirs())) {
return false;
}
- boolean flag = true;
+
File[] files = srcDir.listFiles();
- for (int i = 0; i < files.length; i++) {
- if (files[i].isFile()) {
- flag = copyFile(files[i].getAbsolutePath(), destDirName + files[i].getName(), true);
- } else if (files[i].isDirectory()) {
- flag = copyDirectory(files[i].getAbsolutePath(), destDirName + files[i].getName(), overlay);
- }
- if (!flag) {
- String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!";
- LOGGER.error(message);
- return false;
+
+ return copyInDirectory(srcDirName, destDirName, files, overlay);
+ }
+
+ /**
+ * copy byte.
+ * @param srcFileName source file name
+ * @param destFileName target file name
+ * @return boolean
+ */
+ public static boolean copyByte(File srcFile, File destFile)
+ {
+ try (
+ InputStream in = new FileInputStream(srcFile);
+ OutputStream out = new FileOutputStream(destFile);
+ ) {
+
+ byte[] buffer = new byte[1024];
+ int byteread = 0;
+
+ while ((byteread = in.read(buffer)) != -1) {
+ out.write(buffer, 0, byteread);
}
+ return true;
+ } catch (IOException e) {
+ LOGGER.error("IOException in copyFile", e);
+ return false;
}
-
- return true;
}
/**
@@ -98,23 +142,7 @@ public class ToolUtil {
return false;
}
- int byteread = 0;
-
- try (
- InputStream in = new FileInputStream(srcFile);
- OutputStream out = new FileOutputStream(destFile);
- ) {
- byte[] buffer = new byte[1024];
-
- while ((byteread = in.read(buffer)) != -1) {
- out.write(buffer, 0, byteread);
- }
- return true;
- } catch (IOException e) {
- LOGGER.error("IOException in copyFile", e);
- return false;
- }
-
+ return copyByte(srcFile, destFile);
}
/**